From 39f653eb882dffa2f69209d192093f23588ff176 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 7 Dec 2018 20:17:10 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lua/je_lua_jin.cpp | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lua/je_lua_jin.h | 36 +++++++++++++++++ src/lua/jin.cpp | 104 ------------------------------------------------- src/lua/jin.h | 36 ----------------- 4 files changed, 140 insertions(+), 140 deletions(-) create mode 100644 src/lua/je_lua_jin.cpp create mode 100644 src/lua/je_lua_jin.h delete mode 100644 src/lua/jin.cpp delete mode 100644 src/lua/jin.h (limited to 'src/lua') diff --git a/src/lua/je_lua_jin.cpp b/src/lua/je_lua_jin.cpp new file mode 100644 index 0000000..3e80015 --- /dev/null +++ b/src/lua/je_lua_jin.cpp @@ -0,0 +1,104 @@ +#include "common/je_lua.h" +#include "common/je_lua_common.h" +#include "modules/je_lua_modules.h" +#include "embed/embed.h" +#include "je_lua_jin.h" + +namespace JinEngine +{ + namespace Lua + { + + LUA_IMPLEMENT int l_getversion(lua_State* L) + { + luax_pushstring(L, VERSION); + return 1; + } + + LUA_IMPLEMENT int l_getAuthor(lua_State* L) + { + luax_pushstring(L, AUTHOR); + return 1; + } + + LUA_IMPLEMENT 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; + } + + LUA_IMPLEMENT int l_revision(lua_State* L) + { + luax_pushnumber(L, REVISION); + return 1; + } + + LUA_IMPLEMENT const luax_Str s[] = { + { "version", VERSION }, + { "author", AUTHOR }, + { "codename", CODE_NAME }, + { 0, 0 } + }; + + LUA_IMPLEMENT const luax_Num n[] = { + { "revision", REVISION }, + { 0, 0 } + }; + + // Register jin module, keep it on the top of stack. + LUA_EXPORT void open(lua_State* L) + { + luax_globaltable(L, MODULE_NAME); + + // Register values. + luax_setfieldstrings(L, s); + luax_setfieldnumbers(L, n); + + luax_Reg modules[] = { + { "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 sub modules. + for (int i = 0; modules[i].name; ++i) + { + modules[i].func(L); + luax_setfield(L, -2, modules[i].name); + } + + // Pop jin table. + luax_pop(L, 1); + } + + LUA_EXPORT void boot(lua_State* L, const char* cwd) + { + luax_getglobal(L, MODULE_NAME); + luax_newtable(L); + luax_setfieldstring(L, "cwd", cwd); + luax_setfield(L, -2, "args"); + Embed::load(L); + luax_clearstack(L); + Embed::run(L); + } + + } // namespace Lua +} // namespace JinEngine \ No newline at end of file diff --git a/src/lua/je_lua_jin.h b/src/lua/je_lua_jin.h new file mode 100644 index 0000000..7b38ce7 --- /dev/null +++ b/src/lua/je_lua_jin.h @@ -0,0 +1,36 @@ +/** +* Copyright (C) 2016~2018 chai +*/ + +#ifndef __JIN_M_JIN_H__ +#define __JIN_M_JIN_H__ + +#include "common/je_lua.h" +#include "common/je_lua_common.h" + +#define MODULE_NAME "jin" +#define CODE_NAME "Side Part" +#define VERSION "0.1.1" +#define REVISION_S "101" +#define REVISION 101 +#define AUTHOR "chai" + +namespace JinEngine +{ + namespace Lua + { + + /// + /// open jin module. + /// + LUA_EXPORT void open(lua_State* L); + + /// + /// Boot jin. + /// + LUA_EXPORT void boot(lua_State* L, const char* cwd); + + } // namespace JinEngine +} // namespace Lua + +#endif // __JIN_M_JIN_H__ \ No newline at end of file diff --git a/src/lua/jin.cpp b/src/lua/jin.cpp deleted file mode 100644 index 79a7bf8..0000000 --- a/src/lua/jin.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "common/je_lua.h" -#include "common/je_lua_common.h" -#include "modules/je_lua_modules.h" -#include "embed/embed.h" -#include "jin.h" - -namespace JinEngine -{ - namespace Lua - { - - LUA_IMPLEMENT int l_getversion(lua_State* L) - { - luax_pushstring(L, VERSION); - return 1; - } - - LUA_IMPLEMENT int l_getAuthor(lua_State* L) - { - luax_pushstring(L, AUTHOR); - return 1; - } - - LUA_IMPLEMENT 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; - } - - LUA_IMPLEMENT int l_revision(lua_State* L) - { - luax_pushnumber(L, REVISION); - return 1; - } - - LUA_IMPLEMENT const luax_Str s[] = { - { "version", VERSION }, - { "author", AUTHOR }, - { "codename", CODE_NAME }, - { 0, 0 } - }; - - LUA_IMPLEMENT const luax_Num n[] = { - { "revision", REVISION }, - { 0, 0 } - }; - - // Register jin module, keep it on the top of stack. - LUA_EXPORT void open(lua_State* L) - { - luax_globaltable(L, MODULE_NAME); - - // Register values. - luax_setfieldstrings(L, s); - luax_setfieldnumbers(L, n); - - luax_Reg modules[] = { - { "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 sub modules. - for (int i = 0; modules[i].name; ++i) - { - modules[i].func(L); - luax_setfield(L, -2, modules[i].name); - } - - // Pop jin table. - luax_pop(L, 1); - } - - LUA_EXPORT void boot(lua_State* L, const char* cwd) - { - luax_getglobal(L, MODULE_NAME); - luax_newtable(L); - luax_setfieldstring(L, "cwd", cwd); - luax_setfield(L, -2, "args"); - Embed::load(L); - luax_clearstack(L); - Embed::run(L); - } - - } // namespace Lua -} // namespace JinEngine \ No newline at end of file diff --git a/src/lua/jin.h b/src/lua/jin.h deleted file mode 100644 index 7b38ce7..0000000 --- a/src/lua/jin.h +++ /dev/null @@ -1,36 +0,0 @@ -/** -* Copyright (C) 2016~2018 chai -*/ - -#ifndef __JIN_M_JIN_H__ -#define __JIN_M_JIN_H__ - -#include "common/je_lua.h" -#include "common/je_lua_common.h" - -#define MODULE_NAME "jin" -#define CODE_NAME "Side Part" -#define VERSION "0.1.1" -#define REVISION_S "101" -#define REVISION 101 -#define AUTHOR "chai" - -namespace JinEngine -{ - namespace Lua - { - - /// - /// open jin module. - /// - LUA_EXPORT void open(lua_State* L); - - /// - /// Boot jin. - /// - LUA_EXPORT void boot(lua_State* L, const char* cwd); - - } // namespace JinEngine -} // namespace Lua - -#endif // __JIN_M_JIN_H__ \ No newline at end of file -- cgit v1.1-26-g67d0