diff options
Diffstat (limited to 'src/02-enum')
| -rw-r--r-- | src/02-enum/enum.lua | 26 | ||||
| -rw-r--r-- | src/02-enum/main.cpp | 42 |
2 files changed, 68 insertions, 0 deletions
diff --git a/src/02-enum/enum.lua b/src/02-enum/enum.lua new file mode 100644 index 0000000..9c64c1f --- /dev/null +++ b/src/02-enum/enum.lua @@ -0,0 +1,26 @@ +local function makeEnum(enumtable) + if enumtable == nil or type(enumtable) ~= "table" then + return nil + end + enumtable.__index = enumtable + enumtable.__newindex = function() + print("can not modify enum") + end + local e = {} + setmetatable(e, enumtable) + return e +end + +local function main() + local mode = makeEnum({ + SinglePlayer = 1, + TwoPlayers= 2, + ThreePlayers= 3, + FourPlayers= 4, + PVCom= 5, + }) + mode.SinglePlayer = 2 + print(mode.SinglePlayer) +end + +main()
\ No newline at end of file diff --git a/src/02-enum/main.cpp b/src/02-enum/main.cpp new file mode 100644 index 0000000..172364b --- /dev/null +++ b/src/02-enum/main.cpp @@ -0,0 +1,42 @@ +#include "../configure.h" +#if BUILD_TEST == TEST_2 + +extern "C" { +#include "../lua51/lua.h" +#include "../lua51/lualib.h" +#include "../lua51/lauxlib.h" +} + +#include <windows.h> +#include <time.h> +#include <conio.h> + +luaL_reg fns[] = { + {0, 0} +}; + +void openlibs(lua_State* L) +{ + luaL_openlibs(L); + //luaL_register(L, NULL, fns); + luaL_reg* fn; + int i = 0; + for (fn = &fns[0]; fn->name != 0; fn = &fns[++i]) + { + lua_pushcfunction(L, fn->func); + lua_setglobal(L, fn->name); + } +} + +int main(int args, char* argv[]) +{ + lua_State* L = luaL_newstate(); + openlibs(L); + + luaL_dofile(L, "02-enum/enum.lua"); + + lua_close(L); + return 0; +} + +#endif
\ No newline at end of file |
