diff options
Diffstat (limited to 'src/lua')
-rw-r--r-- | src/lua/modules/embed/embed.h | 17 | ||||
-rw-r--r-- | src/lua/modules/filesystem/filesystem.cpp | 60 | ||||
-rw-r--r-- | src/lua/modules/graphics/graphics.cpp | 14 | ||||
-rw-r--r-- | src/lua/modules/keyboard/keyboard.cpp | 1 | ||||
-rw-r--r-- | src/lua/modules/mouse/mouse.cpp | 12 |
5 files changed, 63 insertions, 41 deletions
diff --git a/src/lua/modules/embed/embed.h b/src/lua/modules/embed/embed.h index 6393454..8d0ba85 100644 --- a/src/lua/modules/embed/embed.h +++ b/src/lua/modules/embed/embed.h @@ -22,21 +22,20 @@ namespace embed static void boot(lua_State* L) { // embed scripts - #include "graphics.lua.h" // graphics - #include "keyboard.lua.h" // keyboard - #include "mouse.lua.h" // mouse - #include "boot.lua.h" // boot + #include "graphics.lua.h" + #include "keyboard.lua.h" + #include "mouse.lua.h" + #include "boot.lua.h" - // embed scripts + // in order const jin_Embed scripts[] = { { "graphics.lua", graphics_lua }, { "keyboard.lua", keyboard_lua }, - { "mouse.lua", mouse_lua }, - { "boot.lua", boot_lua }, - { 0, 0 } + { "mouse.lua", mouse_lua }, + { "boot.lua", boot_lua }, + { 0, 0 } }; - // load all emebd lua scripts for (int i = 0; scripts[i].file; ++i) embed(L, scripts[i].source, scripts[i].file); } diff --git a/src/lua/modules/filesystem/filesystem.cpp b/src/lua/modules/filesystem/filesystem.cpp index 55f4c06..e1d496e 100644 --- a/src/lua/modules/filesystem/filesystem.cpp +++ b/src/lua/modules/filesystem/filesystem.cpp @@ -20,10 +20,6 @@ namespace lua return 0; } - /** - * set current game root, like - * C:/jin/games/tank/ - */ static int l_mount(lua_State* L) { const char* path = luax_checkstring(L, 1); @@ -31,38 +27,31 @@ namespace lua return 0; } - /** - * - */ - static int l_isDir(lua_State *L) + static int l_exist(lua_State * L) { const char* path = luax_checkstring(L, 1); - int r = context.fs->isDir(path); - luax_pushboolean(L, r); - return 1; + int r = context.fs->exists(path); + luax_pushboolean(L, r); + return 1; } - /** - * - */ - static int l_exist(lua_State * L) + static int l_isDir(lua_State* L) { const char* path = luax_checkstring(L, 1); - int r = context.fs->exists(path); + int r = context.fs->isDir(path); luax_pushboolean(L, r); return 1; } - static int l_isdir(lua_State* L) + static int l_isFile(lua_State* L) { const char* path = luax_checkstring(L, 1); - int r = context.fs->isDir(path); + int r = context.fs->isFile(path); luax_pushboolean(L, r); return 1; } - // load but dont run it - static int loadf(lua_State* L) + static int loadbuffer(lua_State* L) { const char* filename = lua_tostring(L, -1); Buffer bf; @@ -92,7 +81,7 @@ namespace lua { lua_pop(L, 1); lua_pushstring(L, tmp.c_str()); - return loadf(L); + return loadbuffer(L); } tmp = filename; @@ -110,7 +99,7 @@ namespace lua { lua_pop(L, 1); lua_pushstring(L, tmp.c_str()); - return loadf(L); + return loadbuffer(L); } } @@ -118,12 +107,25 @@ namespace lua return 1; } + static int l_read(lua_State* L) + { + Filesystem* fs = context.fs; + const char* file = luax_checkstring(L, 1); + unsigned int len; + char* data = (char*)fs->read(file, &len); + luax_pushstring(L, data); + luax_pushinteger(L, len); + return 2; + } + static const luaL_Reg f[] = { - { "init", l_init }, - { "mount", l_mount }, - { "isdir", l_isDir }, - { "exist", l_exist }, - { 0, 0 } + { "init", l_init }, + { "mount", l_mount }, + { "isDir", l_isDir }, + { "isFile", l_isFile }, + { "exist", l_exist }, + { "read", l_read }, + { 0, 0 } }; int luaopen_filesystem(lua_State* L) @@ -133,5 +135,5 @@ namespace lua return 0; } -} -}
\ No newline at end of file +} // filesystem +} // jin
\ No newline at end of file diff --git a/src/lua/modules/graphics/graphics.cpp b/src/lua/modules/graphics/graphics.cpp index cd79211..fadc59d 100644 --- a/src/lua/modules/graphics/graphics.cpp +++ b/src/lua/modules/graphics/graphics.cpp @@ -42,6 +42,14 @@ namespace lua return 1; } + static int l_setTitle(lua_State* L) + { + Window* wnd = Window::get(); + const char* title = luax_checkstring(L, 1); + wnd->setTitle(title); + return 0; + } + static int l_destroy(lua_State* L) { Window* wnd = Window::get(); @@ -189,7 +197,10 @@ namespace lua context.curRenderColor.rgba.r = luax_checknumber(L, 1); context.curRenderColor.rgba.g = luax_checknumber(L, 2); context.curRenderColor.rgba.b = luax_checknumber(L, 3); - context.curRenderColor.rgba.a = luax_checknumber(L, 4); + if (luax_gettop(L) == 4) + context.curRenderColor.rgba.a = luax_checknumber(L, 4); + else + context.curClearColor.rgba.a = 255; glColor4f(context.curRenderColor.rgba.r / 255.f, context.curRenderColor.rgba.g / 255.f, @@ -463,6 +474,7 @@ namespace lua static const luaL_Reg f[] = { { "init", l_init }, + { "setTitle", l_setTitle }, { "getSize", l_getSize }, { "getWidth", l_getWidth }, { "getHeight", l_getHeight }, diff --git a/src/lua/modules/keyboard/keyboard.cpp b/src/lua/modules/keyboard/keyboard.cpp index 9d27a4f..0df9562 100644 --- a/src/lua/modules/keyboard/keyboard.cpp +++ b/src/lua/modules/keyboard/keyboard.cpp @@ -5,6 +5,7 @@ namespace jin { namespace lua { + //https://wiki.libsdl.org/SDL_Keycode int luaopen_keyboard(lua_State* L) { diff --git a/src/lua/modules/mouse/mouse.cpp b/src/lua/modules/mouse/mouse.cpp index f907abb..b7ce933 100644 --- a/src/lua/modules/mouse/mouse.cpp +++ b/src/lua/modules/mouse/mouse.cpp @@ -17,9 +17,17 @@ namespace lua return 2; } + static int l_setVisible(lua_State* L) + { + bool visible = luax_checkbool(L, 1); + SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE); + return 0; + } + static const luaL_Reg f[] = { - { "position", l_pos }, - { 0, 0 } + { "position", l_pos }, + { "setVisible", l_setVisible }, + { 0, 0 } }; int luaopen_mouse(lua_State* L) |