aboutsummaryrefslogtreecommitdiff
path: root/src/lua/jin.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-10-23 12:23:58 +0800
committerchai <chaifix@163.com>2018-10-23 12:23:58 +0800
commit40fc27154fe754181934dc7ee31375e6bdfb33fc (patch)
tree897ad98d759bc308ef66561181ba88b85f2ccd47 /src/lua/jin.cpp
parent1480c9445100075c9e1a894eb07c0ef727b509a1 (diff)
*merge from minimal
Diffstat (limited to 'src/lua/jin.cpp')
-rw-r--r--src/lua/jin.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/lua/jin.cpp b/src/lua/jin.cpp
new file mode 100644
index 0000000..faae9b2
--- /dev/null
+++ b/src/lua/jin.cpp
@@ -0,0 +1,110 @@
+#include "jin.h"
+#include "lua/modules/luax.h"
+#include "embed/embed.h"
+
+namespace JinEngine
+{
+ namespace Lua
+ {
+
+ extern int luaopen_core(lua_State* L);
+ extern int luaopen_graphics(lua_State* L);
+ extern int luaopen_audio(lua_State* L);
+ extern int luaopen_net(lua_State* L);
+ extern int luaopen_event(lua_State* L);
+ extern int luaopen_time(lua_State* L);
+ extern int luaopen_mouse(lua_State* L);
+ extern int luaopen_keyboard(lua_State* L);
+ extern int luaopen_filesystem(lua_State* L);
+ extern int luaopen_joypad(lua_State* L);
+ extern int luaopen_math(lua_State* L);
+ extern int luaopen_thread(lua_State* L);
+ extern int luaopen_bit(lua_State* L);
+
+ static int l_getversion(lua_State* L)
+ {
+ luax_pushstring(L, VERSION);
+ return 1;
+ }
+
+ static int l_getAuthor(lua_State* L)
+ {
+ luax_pushstring(L, AUTHOR);
+ return 1;
+ }
+
+ static int l_getOS(lua_State* L)
+ {
+ #ifdef _WIN32
+ luax_pushstring(L, "windows");
+ #elif defined __unix__
+ luax_pushstring(L, "unix");
+ #elif defined __APPLE__
+ luax_pushstring(L, "macos");
+ #endif
+ return 1;
+ }
+
+ static int l_revision(lua_State* L)
+ {
+ luax_pushnumber(L, REVISION);
+ return 1;
+ }
+
+ static const luax_Str s[] = {
+ { "version", VERSION },
+ { "author", AUTHOR },
+ { "codename", CODE_NAME },
+ { 0, 0 }
+ };
+
+ static const luax_Num n[] = {
+ { "revision", REVISION },
+ { 0, 0 }
+ };
+
+ /* sub modules */
+ static const luax_Ref mods[] = {
+ { "core", luaopen_core },
+ { "event", luaopen_event },
+ { "graphics", luaopen_graphics },
+ { "time", luaopen_time },
+ { "mouse", luaopen_mouse },
+ { "keyboard", luaopen_keyboard },
+ { "filesystem", luaopen_filesystem },
+ { "net", luaopen_net },
+ { "audio", luaopen_audio },
+ { "joypad", luaopen_joypad },
+ { "math", luaopen_math },
+ { "thread", luaopen_thread },
+ { "bit", luaopen_bit },
+ //{"ai", luaopen_ai },
+ { 0, 0 }
+ };
+
+ /* register jin module, keep it on the top of stack */
+ int luaopen_jin(lua_State* L)
+ {
+ luax_globaltable(L, MODULE_NAME);
+
+ /* register values */
+ luax_setfieldstrings(L, s);
+ luax_setfieldnumbers(L, n);
+
+ /* register submodules */
+ for (int i = 0; mods[i].name; ++i)
+ {
+ mods[i].func(L);
+ luax_setfield(L, -2, mods[i].name);
+ }
+
+ return 1;
+ }
+
+ void boot(lua_State* L)
+ {
+ JinEngine::embed::boot(L);
+ }
+
+ } // namespace Lua
+} // namespace JinEngine \ No newline at end of file