aboutsummaryrefslogtreecommitdiff
path: root/src/lua/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua/modules')
-rw-r--r--src/lua/modules/_embed/boot.lua.h6
-rw-r--r--src/lua/modules/event/event.cpp46
-rw-r--r--src/lua/modules/filesystem/filesystem.cpp2
-rw-r--r--src/lua/modules/graphics/graphics.cpp12
-rw-r--r--src/lua/modules/jin.cpp28
-rw-r--r--src/lua/modules/jin.h3
6 files changed, 49 insertions, 48 deletions
diff --git a/src/lua/modules/_embed/boot.lua.h b/src/lua/modules/_embed/boot.lua.h
index 8ff89ee..f7ffc43 100644
--- a/src/lua/modules/_embed/boot.lua.h
+++ b/src/lua/modules/_embed/boot.lua.h
@@ -1,8 +1,8 @@
/* boot.lua */
static const char* boot_lua = R"(
-jin._argv[2] = jin._argv[2] or '.'
+jin.args[2] = jin.args[2] or '.'
jin.filesystem.init()
-jin.filesystem.mount(jin._argv[2])
+jin.filesystem.mount(jin.args[2])
-------------------------------------------------------------------------
-- Config game
@@ -15,7 +15,7 @@ end
jin.config.width = jin.config.width or 576
jin.config.height = jin.config.height or 448
jin.config.vsync = jin.config.vsync or true
-jin.config.title = jin.config.title or ("jin v" .. jin.version())
+jin.config.title = jin.config.title or ("jin v" .. jin.version)
jin.config.resizable = jin.config.resizable or false
jin.config.fullscreen = jin.config.fullscreen or false
jin.config.fps = jin.config.fps or 60
diff --git a/src/lua/modules/event/event.cpp b/src/lua/modules/event/event.cpp
index 08d52e0..0fb438f 100644
--- a/src/lua/modules/event/event.cpp
+++ b/src/lua/modules/event/event.cpp
@@ -31,53 +31,53 @@ namespace lua
switch (e.type)
{
case EventType::QUIT:
- luax_setfield_string(L, "type", "Quit");
+ luax_setfieldstring(L, "type", "Quit");
break;
case EventType::KEY_DOWN:
- luax_setfield_string(L, "type", "KeyDown");
- luax_setfield_string(L, "key", getKeyName(e.key.keysym.sym));
+ luax_setfieldstring(L, "type", "KeyDown");
+ luax_setfieldstring(L, "key", getKeyName(e.key.keysym.sym));
break;
case EventType::KEY_UP:
- luax_setfield_string(L, "type", "KeyUp");
- luax_setfield_string(L, "key", getKeyName(e.key.keysym.sym));
+ luax_setfieldstring(L, "type", "KeyUp");
+ luax_setfieldstring(L, "key", getKeyName(e.key.keysym.sym));
break;
case EventType::MOUSE_MOTION:
- luax_setfield_string(L, "type", "MouseMotion");
- luax_setfield_number(L, "x", e.motion.x);
- luax_setfield_number(L, "y", e.motion.y);
+ luax_setfieldstring(L, "type", "MouseMotion");
+ luax_setfieldnumber(L, "x", e.motion.x);
+ luax_setfieldnumber(L, "y", e.motion.y);
break;
case EventType::MOUSE_BUTTON_DOWN:
- luax_setfield_string(L, "type", "MouseButtonDown");
- luax_setfield_string(L, "button", getButtonName(e.button.button));
- luax_setfield_number(L, "x", e.button.x);
- luax_setfield_number(L, "y", e.button.y);
+ luax_setfieldstring(L, "type", "MouseButtonDown");
+ luax_setfieldstring(L, "button", getButtonName(e.button.button));
+ luax_setfieldnumber(L, "x", e.button.x);
+ luax_setfieldnumber(L, "y", e.button.y);
break;
case EventType::MOUSE_BUTTON_UP:
- luax_setfield_string(L, "type", "MouseButtonUp");
- luax_setfield_string(L, "button", getButtonName(e.button.button));
- luax_setfield_number(L, "x", e.button.x);
- luax_setfield_number(L, "y", e.button.y);
+ luax_setfieldstring(L, "type", "MouseButtonUp");
+ luax_setfieldstring(L, "button", getButtonName(e.button.button));
+ luax_setfieldnumber(L, "x", e.button.x);
+ luax_setfieldnumber(L, "y", e.button.y);
break;
case EventType::MOUSE_WHEEL:
- luax_setfield_string(L, "type", "Wheel");
+ luax_setfieldstring(L, "type", "Wheel");
if(e.wheel.x == -1)
- luax_setfield_string(L, "x", "Left");
+ luax_setfieldstring(L, "x", "Left");
else if(e.wheel.x == 1)
- luax_setfield_string(L, "x", "Right");
+ luax_setfieldstring(L, "x", "Right");
else
- luax_setfield_string(L, "x", "None");
+ luax_setfieldstring(L, "x", "None");
if (e.wheel.y == -1)
- luax_setfield_string(L, "y", "Near");
+ luax_setfieldstring(L, "y", "Near");
else if (e.wheel.y == 1)
- luax_setfield_string(L, "y", "Far");
+ luax_setfieldstring(L, "y", "Far");
else
- luax_setfield_string(L, "y", "None");
+ luax_setfieldstring(L, "y", "None");
break;
default:
diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/filesystem.cpp
index 1fc0d7c..c3dabad 100644
--- a/src/lua/modules/filesystem/filesystem.cpp
+++ b/src/lua/modules/filesystem/filesystem.cpp
@@ -132,7 +132,7 @@ namespace lua
int luaopen_filesystem(lua_State* L)
{
luax_newlib(L, f);
- luax_register_searcher(L, loader, 1);
+ luax_registersearcher(L, loader, 1);
return 0;
}
diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp
index a8c54c2..d662cc7 100644
--- a/src/lua/modules/graphics/graphics.cpp
+++ b/src/lua/modules/graphics/graphics.cpp
@@ -25,12 +25,12 @@ namespace lua
{
Window* wnd = Window::get();
Window::Setting setting;
- setting.width = luax_getfield_integer(L, 1, "width");
- setting.height = luax_getfield_integer(L, 1, "height");
- setting.title = luax_getfield_string(L, 1, "title");
- setting.vsync = luax_getfield_bool(L, 1, "vsync");
- setting.fullscreen = luax_getfield_bool(L, 1, "fullscreen");
- setting.resizable = luax_getfield_bool(L, 1, "resizable");
+ setting.width = luax_getfieldinteger(L, 1, "width");
+ setting.height = luax_getfieldinteger(L, 1, "height");
+ setting.title = luax_getfieldstring(L, 1, "title");
+ setting.vsync = luax_getfieldbool(L, 1, "vsync");
+ setting.fullscreen = luax_getfieldbool(L, 1, "fullscreen");
+ setting.resizable = luax_getfieldbool(L, 1, "resizable");
if (!wnd->init(&setting))
{
luax_pushboolean(L, false);
diff --git a/src/lua/modules/jin.cpp b/src/lua/modules/jin.cpp
index a287218..de49846 100644
--- a/src/lua/modules/jin.cpp
+++ b/src/lua/modules/jin.cpp
@@ -51,16 +51,16 @@ namespace lua
return 1;
}
- static const luaL_Reg f[] = {
- { "version", l_getversion },
- { "revision", l_revision },
- { "author", l_getAuthor },
- { "os", l_getOS },
- { 0, 0 }
+ static const luax_Str s[] = {
+ { "version", VERSION },
+ { "revision", REVISION_S },
+ { "author", AUTHOR },
+ { "codename", CODE_NAME },
+ { 0, 0 }
};
-
- // submodules
- static const luaL_Reg mods[] = {
+
+ /* sub modules */
+ static const luax_Ref mods[] = {
{ "core", luaopen_core },
{ "event", luaopen_event },
{ "graphics", luaopen_graphics },
@@ -77,15 +77,15 @@ namespace lua
{ 0, 0 }
};
+ /* register jin module, keep it on the top of stack */
int luaopen_jin(lua_State* L)
{
- // jin module is on top of the stack
- luax_newlib(L, f);
+ luax_globaltable(L, MODULE_NAME);
- // set to global field
- luax_justglobal(L, -1, MODULE_NAME);
+ /* register strings */
+ luax_setfieldstrings(L, s);
- // register submodules
+ /* register submodules */
for (int i = 0; mods[i].name; ++i)
{
mods[i].func(L);
diff --git a/src/lua/modules/jin.h b/src/lua/modules/jin.h
index 2cc01f0..fe8d6dd 100644
--- a/src/lua/modules/jin.h
+++ b/src/lua/modules/jin.h
@@ -9,7 +9,8 @@
#define MODULE_NAME "jin"
#define CODE_NAME "Side Part"
#define VERSION "0.1.1"
-#define REVISION 101
+#define REVISION_S "101"
+#define REVISION 101
#define AUTHOR "chai"
namespace jin