diff options
Diffstat (limited to 'src')
38 files changed, 281 insertions, 165 deletions
diff --git a/src/libjin/graphics/animations/je_animator.cpp b/src/libjin/graphics/animations/je_animator.cpp index 9550116..e15dc90 100644 --- a/src/libjin/graphics/animations/je_animator.cpp +++ b/src/libjin/graphics/animations/je_animator.cpp @@ -113,6 +113,11 @@ namespace JinEngine } } + float Animator::getSpeed() + { + return mSpeed; + } + } } }
\ No newline at end of file diff --git a/src/libjin/graphics/animations/je_animator.h b/src/libjin/graphics/animations/je_animator.h index ad8138d..d3fdbae 100644 --- a/src/libjin/graphics/animations/je_animator.h +++ b/src/libjin/graphics/animations/je_animator.h @@ -43,6 +43,8 @@ namespace JinEngine void setDefaultLoop(); + float getSpeed(); + private: const Animation* mAnimation; diff --git a/src/lua/common/je_lua.cpp b/src/lua/common/je_lua.cpp new file mode 100644 index 0000000..748606b --- /dev/null +++ b/src/lua/common/je_lua.cpp @@ -0,0 +1,79 @@ +#include "je_lua.h" + +namespace JinEngine +{ + namespace Lua + { + + /// + /// Lua objects table. Map object to proxy, like objects_table[object] = proxy. + /// + static const char* Jin_Lua_Objects_Table = "Jin_Objects_Table"; + + /// + /// Lua modules table. Map object to proxy, like modules_table[object] = module. + /// + static const char* Jin_Lua_Modules_Table = "Jin_Modules_Table"; + + /// + /// Lua references table. Map object to proxy, like references[object] = ref. + /// + static const char* Jin_Lua_Reference_Table = "Jin_Reference_Table"; + + Proxy* luax_newinstance(lua_State* L, const char* type, SharedBase* shared) + { + Proxy* proxy = static_cast<Proxy*>(luax_newinstance(L, type, sizeof(Proxy))); + if (shared) proxy->bind(shared); + luax_getobjectstable(L); + // Add to objects_table, like objects_table[shared] = proxy + luax_pushlightuserdata(L, shared); + luax_pushvalue(L, -3); + luax_settable(L, -3); + luax_pop(L, 1); // Pop objects table. + return proxy; + } + + int luax_getobject(lua_State* L, SharedBase* shadred) + { + luax_getobjectstable(L); + luax_pushlightuserdata(L, shadred); + luax_gettable(L, -2); + luax_remove(L, -2); // Remove objects table on stack. + return 1; + } + + int luax_getregistrytable(lua_State* L, const char* tbl) + { + luax_getfield(L, LUA_REGISTRYINDEX, tbl); + // If no such table, add one. + if (luax_isnil(L, -1) || !luax_istable(L, -1)) + { + luax_pop(L, 1); + luax_newtable(L); + luax_pushstring(L, tbl); + luax_pushvalue(L, -2); + luax_settable(L, LUA_REGISTRYINDEX); + } + return 1; + } + + int luax_getobjectstable(lua_State* L) + { + luax_getregistrytable(L, Jin_Lua_Objects_Table); + return 1; + } + + int luax_getmodulestable(lua_State* L) + { + luax_getregistrytable(L, Jin_Lua_Modules_Table); + return 1; + } + + int luax_getreferencestable(lua_State* L) + { + luax_getregistrytable(L, Jin_Lua_Reference_Table); + return 1; + } + + } +}
\ No newline at end of file diff --git a/src/lua/common/je_lua.h b/src/lua/common/je_lua.h new file mode 100644 index 0000000..c345b2a --- /dev/null +++ b/src/lua/common/je_lua.h @@ -0,0 +1,54 @@ +#ifndef __JE_LUA_H__ +#define __JE_LUA_H__ +#include "LuaJIT/lua.hpp" +#include "libraries/luax/luax.h" + +#include "je_lua_proxy.h" +#include "je_lua_reference.h" +#include "je_lua_shared.hpp" + +namespace JinEngine +{ + namespace Lua + { + + extern const char* Jin_Lua_Objects_Table; + + extern const char* Jin_Lua_Modules_Table; + + extern const char* Jin_Lua_Reference_Table; + + /// + /// + /// + Proxy* luax_newinstance(lua_State* L, const char* type, SharedBase* shared); + + /// + /// + /// + int luax_getobject(lua_State* L, SharedBase* shared); + + /// + /// + /// + int luax_getobjectstable(lua_State* L); + + /// + /// + /// + int luax_getmodulestable(lua_State* L); + + /// + /// + /// + int luax_getreferencestable(lua_State* L); + + /// + /// + /// + int luax_getregistrytable(lua_State* L, const char* tbl); + + } +} + +#endif
\ No newline at end of file diff --git a/src/lua/common/je_lua_error.h b/src/lua/common/je_lua_error.h index e0f7f35..bd5695d 100644 --- a/src/lua/common/je_lua_error.h +++ b/src/lua/common/je_lua_error.h @@ -3,8 +3,7 @@ #include <string.h> -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "common/je_lua.h" namespace JinEngine { diff --git a/src/lua/common/je_lua_proxy.h b/src/lua/common/je_lua_proxy.h index 17e8da7..d6a6a0a 100644 --- a/src/lua/common/je_lua_proxy.h +++ b/src/lua/common/je_lua_proxy.h @@ -1,9 +1,6 @@ #ifndef __JIN_COMMON_PROXY_H #define __JIN_COMMON_PROXY_H -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" - #include "je_lua_shared.hpp" namespace JinEngine @@ -57,14 +54,6 @@ namespace JinEngine }; - inline Proxy* luax_newinstance(lua_State* L, const char* type, SharedBase* shared = nullptr) - { - Proxy* proxy = static_cast<Proxy*>(luax_newinstance(L, type, sizeof(Proxy))); - if(shared) - proxy->bind(shared); - return proxy; - } - } // namespace Lua } // namespace JinEngine diff --git a/src/lua/common/je_lua_reference.cpp b/src/lua/common/je_lua_reference.cpp index 05dc82b..37ed441 100644 --- a/src/lua/common/je_lua_reference.cpp +++ b/src/lua/common/je_lua_reference.cpp @@ -1,7 +1,6 @@ -#include "je_lua_reference.h" +#include "common/je_lua.h" -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "je_lua_reference.h" namespace JinEngine { @@ -12,7 +11,10 @@ namespace JinEngine : mL(L) { luax_pushvalue(mL, i); - mIndex = luax_ref(mL, LUA_REGISTRYINDEX); + luax_getreferencestable(L); + luax_pushvalue(mL, -2); + mIndex = luax_ref(mL, -2); + luax_pop(L, 3); } LuaRef::~LuaRef() @@ -22,12 +24,16 @@ namespace JinEngine void LuaRef::unref() { - luax_unref(mL, LUA_REGISTRYINDEX, mIndex); + luax_getreferencestable(mL); + luax_unref(mL, -1, mIndex); + luax_pop(mL, 1); } void LuaRef::push() { - luax_rawgeti(mL, LUA_REGISTRYINDEX, mIndex); + luax_getreferencestable(mL); + luax_rawgeti(mL, -1, mIndex); + luax_remove(mL, -2); } } diff --git a/src/lua/common/je_lua_reference.h b/src/lua/common/je_lua_reference.h index 84115a6..1a62dba 100644 --- a/src/lua/common/je_lua_reference.h +++ b/src/lua/common/je_lua_reference.h @@ -1,8 +1,7 @@ #ifndef __JIN_COMMON_REFERENCE_H #define __JIN_COMMON_REFERENCE_H -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "common/je_lua.h" namespace JinEngine { diff --git a/src/lua/jin.cpp b/src/lua/jin.cpp index 9dc46aa..f4fcb61 100644 --- a/src/lua/jin.cpp +++ b/src/lua/jin.cpp @@ -1,5 +1,4 @@ -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "common/je_lua.h" #include "common/je_lua_common.h" #include "embed/embed.h" #include "jin.h" diff --git a/src/lua/jin.h b/src/lua/jin.h index 0287a54..9042704 100644 --- a/src/lua/jin.h +++ b/src/lua/jin.h @@ -4,8 +4,8 @@ #ifndef __JIN_M_JIN_H #define __JIN_M_JIN_H -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "common/je_lua.h" + #include "common/je_lua_common.h" #define MODULE_NAME "jin" diff --git a/src/lua/libraries/luax/luax.h b/src/lua/libraries/luax/luax.h index 06593e9..fc2b21e 100644 --- a/src/lua/libraries/luax/luax.h +++ b/src/lua/libraries/luax/luax.h @@ -43,6 +43,7 @@ lua_pushvalue(L, i);\ lua_setglobal(L, name); #define luax_pop lua_pop +#define luax_remove lua_remove #define luax_newtable lua_newtable #define luax_getglobal lua_getglobal @@ -59,6 +60,8 @@ #define luax_gettable lua_gettable +#define luax_settable lua_settable + /** * Check userdata type. */ diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp index b9183b2..61b9556 100644 --- a/src/lua/modules/audio/je_lua_audio.cpp +++ b/src/lua/modules/audio/je_lua_audio.cpp @@ -1,5 +1,4 @@ -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "common/je_lua.h" #include "common/je_lua_common.h" #include "libjin/jin.h" #include "je_lua_source.h" @@ -98,8 +97,7 @@ namespace JinEngine luax_pushnil(L); return 1; } - Proxy* proxy = luax_newinstance(L, Jin_Lua_Source); - proxy->bind(new Shared<Source>(src, Jin_Lua_Source)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Source, new Shared<Source>(src, Jin_Lua_Source)); return 1; } @@ -114,7 +112,7 @@ namespace JinEngine { luaopen_Source(L); - luaL_Reg f[] = { + luaL_Reg methods[] = { { "init", l_init }, { "play", l_play }, { "stop", l_stop }, @@ -125,9 +123,7 @@ namespace JinEngine { "destroy", l_destroy }, { 0, 0 } }; - - luax_newlib(L, f); - + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/audio/je_lua_source.cpp b/src/lua/modules/audio/je_lua_source.cpp index 5058690..0e7b09e 100644 --- a/src/lua/modules/audio/je_lua_source.cpp +++ b/src/lua/modules/audio/je_lua_source.cpp @@ -1,6 +1,5 @@ #include "libjin/jin.h" -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "common/je_lua.h" #include "common/je_lua_common.h" using namespace JinEngine::Audio; @@ -96,7 +95,7 @@ namespace JinEngine LUA_EXPORT void luaopen_Source(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { "play", l_play }, { "stop", l_stop }, @@ -110,7 +109,7 @@ namespace JinEngine { 0, 0 } }; - luax_newtype(L, Jin_Lua_Source, f); + luax_newtype(L, Jin_Lua_Source, methods); } } // namespace Lua diff --git a/src/lua/modules/bit/je_lua_bit.cpp b/src/lua/modules/bit/je_lua_bit.cpp index 2759905..6d5a8fd 100644 --- a/src/lua/modules/bit/je_lua_bit.cpp +++ b/src/lua/modules/bit/je_lua_bit.cpp @@ -1,6 +1,5 @@ #include "common/je_lua_common.h" -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "common/je_lua.h" #include "libjin/jin.h" #include <cstdlib> @@ -68,7 +67,7 @@ namespace JinEngine LUA_EXPORT int luaopen_bit(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "bAnd", l_and }, { "bOr" , l_or }, { "bXor", l_xor }, @@ -79,7 +78,7 @@ namespace JinEngine { 0, 0 } }; - luax_newlib(L, f); + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/core/je_lua_core.cpp b/src/lua/modules/core/je_lua_core.cpp index f657910..956ffbe 100644 --- a/src/lua/modules/core/je_lua_core.cpp +++ b/src/lua/modules/core/je_lua_core.cpp @@ -1,6 +1,5 @@ #include "common/je_lua_common.h" -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "common/je_lua.h" #include "libjin/jin.h" using namespace JinEngine::Game; @@ -32,13 +31,13 @@ namespace JinEngine LUA_EXPORT int luaopen_core(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "running", l_running }, { "stop", l_stop }, { "quit", l_quit }, { 0, 0 } }; - luax_newlib(L, f); + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/event/je_lua_event.cpp b/src/lua/modules/event/je_lua_event.cpp index 7fd73c8..8a550d6 100644 --- a/src/lua/modules/event/je_lua_event.cpp +++ b/src/lua/modules/event/je_lua_event.cpp @@ -2,8 +2,7 @@ * Event module */ #include "common/je_lua_common.h" -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "common/je_lua.h" #include "libjin/jin.h" using namespace JinEngine; @@ -118,11 +117,11 @@ namespace JinEngine */ LUA_EXPORT int luaopen_event(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "poll", l_event_poll }, { 0, 0 } }; - luax_newlib(L, f); + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/filesystem/je_lua_filesystem.cpp b/src/lua/modules/filesystem/je_lua_filesystem.cpp index 84b9c01..8bc3a69 100644 --- a/src/lua/modules/filesystem/je_lua_filesystem.cpp +++ b/src/lua/modules/filesystem/je_lua_filesystem.cpp @@ -1,6 +1,5 @@ #include "common/je_lua_common.h" -#include "LuaJIT/lua.hpp" -#include "libraries/luax/luax.h" +#include "common/je_lua.h" #include "libjin/jin.h" #include <string> @@ -123,7 +122,7 @@ namespace JinEngine LUA_EXPORT int luaopen_filesystem(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "init", l_init }, { "mount", l_mount }, { "isDirectory", l_isDir }, @@ -132,7 +131,7 @@ namespace JinEngine { "read", l_read }, { 0, 0 } }; - luax_newlib(L, f); + luax_newlib(L, methods); luax_registersearcher(L, loader, 1); return 0; diff --git a/src/lua/modules/graphics/je_lua_animation.cpp b/src/lua/modules/graphics/je_lua_animation.cpp index 9c4eaeb..d054761 100644 --- a/src/lua/modules/graphics/je_lua_animation.cpp +++ b/src/lua/modules/graphics/je_lua_animation.cpp @@ -85,17 +85,34 @@ namespace JinEngine return 1; } + LUA_IMPLEMENT int l_getFrame(lua_State* L) + { + SharedAnimation shrAnimation = checkAnimation(L); + int i = luax_checkinteger(L, 2); + SharedBase* shrFrame = shrAnimation.getDependency((int)AnimationDependency::DEP_SPRITES + i); + luax_getobject(L, shrFrame); + return 1; + } + + LUA_IMPLEMENT int getFrameCount(lua_State* L) + { + SharedAnimation shrAnimation = checkAnimation(L); + int n = shrAnimation->getFrameCount(); + luax_pushinteger(L, n); + return 1; + } + LUA_EXPORT void luaopen_Animation(lua_State* L) { luaL_Reg methods[] = { - { "__gc", l_gc }, - { "addFrame", l_addFrame }, - { "addFrames", l_addFrames }, - { "isLoop", l_isLoop }, - { "getSpeed", l_getSpeed }, - { "getFrameCount", l_getSpeed }, - //{ "getFrame", l_getFrame }, - { 0, 0 } + { "__gc", l_gc }, + { "addFrame", l_addFrame }, + { "addFrames", l_addFrames }, + { "isLoop", l_isLoop }, + { "getSpeed", l_getSpeed }, + { "getFrameCount", getFrameCount }, + { "getFrame", l_getFrame }, + { 0, 0 } }; luax_newtype(L, Jin_Lua_Animation, methods); } diff --git a/src/lua/modules/graphics/je_lua_animator.cpp b/src/lua/modules/graphics/je_lua_animator.cpp index 519bc75..857d375 100644 --- a/src/lua/modules/graphics/je_lua_animator.cpp +++ b/src/lua/modules/graphics/je_lua_animator.cpp @@ -132,6 +132,14 @@ namespace JinEngine return 0; } + LUA_IMPLEMENT int l_getSpeed(lua_State* L) + { + SharedAnimator shrAnimator = checkAnimator(L); + float speed = shrAnimator->getSpeed(); + luax_pushnumber(L, speed); + return 1; + } + LUA_EXPORT void luaopen_Animator(lua_State* L) { luaL_Reg methods[] = { @@ -148,6 +156,7 @@ namespace JinEngine { "setDefaultSpeed", l_setDefaultSpeed }, { "setLoop", l_setLoop }, { "setDefaultLoop", l_setDefaultLoop }, + { "getSpeed", l_getSpeed }, { 0, 0 } }; luax_newtype(L, Jin_Lua_Animator, methods); diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp index 24641a0..2495fb3 100644 --- a/src/lua/modules/graphics/je_lua_bitmap.cpp +++ b/src/lua/modules/graphics/je_lua_bitmap.cpp @@ -90,14 +90,13 @@ namespace JinEngine SharedBitmap shared = checkBitmap(L); Bitmap* bitmap = shared.getObject(); Bitmap* b = Bitmap::clone(bitmap); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap); - proxy->bind(new Shared<Bitmap>(b, Jin_Lua_Bitmap)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap, new Shared<Bitmap>(b, Jin_Lua_Bitmap)); return 1; } LUA_EXPORT void luaopen_Bitmap(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { "getWidth", l_getWidth }, { "getHeight", l_getHeight }, @@ -107,7 +106,7 @@ namespace JinEngine { "clone", l_clone }, { 0, 0 } }; - luax_newtype(L, Jin_Lua_Bitmap, f); + luax_newtype(L, Jin_Lua_Bitmap, methods); } } // namespace Graphics diff --git a/src/lua/modules/graphics/je_lua_canvas.cpp b/src/lua/modules/graphics/je_lua_canvas.cpp index 3c1e606..5cbcf98 100644 --- a/src/lua/modules/graphics/je_lua_canvas.cpp +++ b/src/lua/modules/graphics/je_lua_canvas.cpp @@ -52,14 +52,14 @@ namespace JinEngine LUA_EXPORT void luaopen_Canvas(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { "getWidth", l_getWidth }, { "getHeight", l_getHeight }, { "getSize", l_getSize }, { 0, 0 } }; - luax_newtype(L, Jin_Lua_Canvas, f); + luax_newtype(L, Jin_Lua_Canvas, methods); } } // namespace Lua diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp index 4ebd1ee..cc67055 100644 --- a/src/lua/modules/graphics/je_lua_graphics.cpp +++ b/src/lua/modules/graphics/je_lua_graphics.cpp @@ -208,8 +208,7 @@ namespace JinEngine return 1; } } - Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap); - proxy->bind(new Shared<Bitmap>(bitmap, Jin_Lua_Bitmap)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap, new Shared<Bitmap>(bitmap, Jin_Lua_Bitmap)); return 1; } @@ -229,8 +228,7 @@ namespace JinEngine const char* path = luax_checkstring(L, 1); texture = Texture::createTexture(path); } - Proxy* proxy = luax_newinstance(L, Jin_Lua_Texture); - proxy->bind(new Shared<Texture>(texture, Jin_Lua_Texture)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Texture, new Shared<Texture>(texture, Jin_Lua_Texture)); return 1; } @@ -244,8 +242,7 @@ namespace JinEngine luax_pushnil(L); return 1; } - Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader); - proxy->bind(new Shared<Shader>(jsl, Jin_Lua_Shader)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader, new Shared<Shader>(jsl, Jin_Lua_Shader)); return 1; } @@ -268,8 +265,7 @@ namespace JinEngine luax_pushnil(L); return 1; } - Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader); - proxy->bind(new Shared<Shader>(jsl, Jin_Lua_Shader)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader, new Shared<Shader>(jsl, Jin_Lua_Shader)); return 1; } @@ -277,9 +273,8 @@ namespace JinEngine { int w = luax_checknumber(L, 1); int h = luax_checknumber(L, 2); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Canvas); Canvas* cvs = Canvas::createCanvas(w, h); - proxy->bind(new Shared<Canvas>(cvs, Jin_Lua_Canvas)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Canvas, new Shared<Canvas>(cvs, Jin_Lua_Canvas)); return 1; } @@ -676,7 +671,6 @@ namespace JinEngine LUA_IMPLEMENT int l_newTTFData(lua_State* L) { - Proxy* proxy = luax_newinstance(L, Jin_Lua_TTFData); TTFData* fd = nullptr; { const char* path = luax_checkstring(L, 1); @@ -691,7 +685,7 @@ namespace JinEngine fs->read(path, b); fd = TTFData::createTTFData(&b, b.size()); } - proxy->bind(new Shared<TTFData>(fd, Jin_Lua_TTFData)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_TTFData, new Shared<TTFData>(fd, Jin_Lua_TTFData)); return 1; } @@ -714,8 +708,7 @@ namespace JinEngine unsigned length; const char* data = luax_checklstring(L, 1, &length); Text* text = new Text(encode, data, length); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Text); - proxy->bind(new Shared<Text>(text, Jin_Lua_Text)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Text, new Shared<Text>(text, Jin_Lua_Text)); return 1; } @@ -743,8 +736,7 @@ namespace JinEngine quad.h = luax_rawgetnumberthenpop(L, 2, 4); int o = luax_checkinteger(L, 3); Origin origin = static_cast<Origin>(o); - Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); - p->bind(new Shared<Sprite>(new Sprite(graphic, quad, origin), Jin_Lua_Sprite)); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(new Sprite(graphic, quad, origin), Jin_Lua_Sprite)); } else if (n == 4) { @@ -755,22 +747,19 @@ namespace JinEngine quad.h = luax_rawgetnumberthenpop(L, 2, 4); int ox = luax_checkinteger(L, 3); int oy = luax_checkinteger(L, 4); - Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); - p->bind(new Shared<Sprite>(new Sprite(graphic, quad, ox, oy), Jin_Lua_Sprite)); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(new Sprite(graphic, quad, ox, oy), Jin_Lua_Sprite)); } else if (n == 2) { int o = luax_checkinteger(L, 2); Origin origin = static_cast<Origin>(o); - Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); - p->bind(new Shared<Sprite>(new Sprite(graphic, origin), Jin_Lua_Sprite)); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(new Sprite(graphic, origin), Jin_Lua_Sprite)); } else if (n == 3) { int ox = luax_checkinteger(L, 2); int oy = luax_checkinteger(L, 3); - Proxy* p = luax_newinstance(L, Jin_Lua_Sprite); - p->bind(new Shared<Sprite>(new Sprite(graphic, ox, oy), Jin_Lua_Sprite)); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(new Sprite(graphic, ox, oy), Jin_Lua_Sprite)); } else { @@ -791,12 +780,11 @@ namespace JinEngine pxyGraphic = (Proxy*)luax_checktype(L, 1, Jin_Lua_Canvas); if (pxyGraphic != nullptr) { - Proxy* pxySSheet = luax_newinstance(L, Jin_Lua_SpriteSheet); Graphic* graphic = pxyGraphic->getObject<Graphic>(); Shared<SpriteSheet>* shrSSheet = new Shared<SpriteSheet>(new SpriteSheet(graphic), Jin_Lua_SpriteSheet); Shared<Graphic>& shrGraphic = pxyGraphic->getShared<Graphic>(); shrSSheet->setDependency((int)SpriteSheetDependency::DEP_GRAPHIC, &shrGraphic); - pxySSheet->bind(shrSSheet); + Proxy* pxySSheet = luax_newinstance(L, Jin_Lua_SpriteSheet, shrSSheet); return 1; } else @@ -830,8 +818,7 @@ namespace JinEngine (*shrAnimation)->setLoop(loop); (*shrAnimation)->setSpeed(speed); } - Proxy* pxyAnimation = luax_newinstance(L, Jin_Lua_Animation); - pxyAnimation->bind(shrAnimation); + Proxy* pxyAnimation = luax_newinstance(L, Jin_Lua_Animation, shrAnimation); return 1; } @@ -847,8 +834,7 @@ namespace JinEngine (*shrAniamtor)->setAnimation(shrAnimtion.getObject()); (*shrAniamtor).setDependency((int)AnimatorDependency::DEP_ANIMATION, &shrAnimtion); } - Proxy* pxyAnimator = luax_newinstance(L, Jin_Lua_Animator); - pxyAnimator->bind(shrAniamtor); + Proxy* pxyAnimator = luax_newinstance(L, Jin_Lua_Animator, shrAniamtor); return 1; } @@ -899,8 +885,7 @@ namespace JinEngine // Delete temporary text. delete text; } - Proxy* proxy = luax_newinstance(L, Jin_Lua_TextureFont); - proxy->bind(new Shared<TextureFont>(textureFont, Jin_Lua_TextureFont)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_TextureFont, new Shared<TextureFont>(textureFont, Jin_Lua_TextureFont)); return 1; } @@ -985,7 +970,7 @@ namespace JinEngine luaopen_Animation(L); luaopen_Animator(L); - luaL_Reg f[] = { + luaL_Reg methods[] = { /* window */ { "init", l_init }, { "setTitle", l_setTitle }, @@ -1041,10 +1026,8 @@ namespace JinEngine { "scale", l_scale }, { 0, 0 } }; - // Load whole lib. - luax_newlib(L, f); - + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/graphics/je_lua_page.cpp b/src/lua/modules/graphics/je_lua_page.cpp index 00a9302..c3fdc7e 100644 --- a/src/lua/modules/graphics/je_lua_page.cpp +++ b/src/lua/modules/graphics/je_lua_page.cpp @@ -55,14 +55,14 @@ namespace JinEngine LUA_EXPORT void luaopen_Page(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { "getSize", l_getSize }, { "getWidth", l_getWidth }, { "getHeight", l_getHeight }, { 0, 0 } }; - luax_newtype(L, Jin_Lua_Page, f); + luax_newtype(L, Jin_Lua_Page, methods); } } // namespace Lua diff --git a/src/lua/modules/graphics/je_lua_shader.cpp b/src/lua/modules/graphics/je_lua_shader.cpp index c04b360..cfe2260 100644 --- a/src/lua/modules/graphics/je_lua_shader.cpp +++ b/src/lua/modules/graphics/je_lua_shader.cpp @@ -119,7 +119,7 @@ namespace JinEngine LUA_EXPORT void luaopen_Shader(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { "sendNumber", l_sendNumber }, { "sendTexture", l_sendTexture }, @@ -130,7 +130,7 @@ namespace JinEngine { "sendColor", l_sendColor }, { 0, 0 } }; - luax_newtype(L, Jin_Lua_Shader, f); + luax_newtype(L, Jin_Lua_Shader, methods); } } // namespace Lua diff --git a/src/lua/modules/graphics/je_lua_spritesheet.cpp b/src/lua/modules/graphics/je_lua_spritesheet.cpp index 9496fbf..57b610c 100644 --- a/src/lua/modules/graphics/je_lua_spritesheet.cpp +++ b/src/lua/modules/graphics/je_lua_spritesheet.cpp @@ -48,10 +48,9 @@ namespace JinEngine origin = static_cast<Origin>(o); spr = sheet->createSprite(quad, origin); } - Proxy* pxySprite = luax_newinstance(L, Jin_Lua_Sprite); Shared<Sprite>* shrSprite = new Shared<Sprite>(spr, Jin_Lua_Sprite); shrSprite->setDependency((int)SpriteDependency::DEP_SPRITESHEET, &shrSSheet); - pxySprite->bind(shrSprite); + Proxy* pxySprite = luax_newinstance(L, Jin_Lua_Sprite, shrSprite); return 1; } @@ -98,10 +97,9 @@ namespace JinEngine for (int i = 0; i < sprs.size(); ++i) { Sprite* spr = sprs[i]; - Proxy* pxys = (Proxy*)luax_newinstance(L, Jin_Lua_Sprite); Shared<Sprite>* shrSpr = new Shared<Sprite>(spr, Jin_Lua_Sprite); shrSpr->setDependency((int)SpriteDependency::DEP_GRAPHIC, shrGraphic); - pxys->bind(shrSpr); + Proxy* pxys = (Proxy*)luax_newinstance(L, Jin_Lua_Sprite, shrSpr); luax_rawseti(L, -2, i + 1); } return 1; diff --git a/src/lua/modules/graphics/je_lua_text.cpp b/src/lua/modules/graphics/je_lua_text.cpp index 0db6c32..6509e73 100644 --- a/src/lua/modules/graphics/je_lua_text.cpp +++ b/src/lua/modules/graphics/je_lua_text.cpp @@ -21,11 +21,11 @@ namespace JinEngine LUA_EXPORT void luaopen_Text(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { 0, 0 } }; - luax_newtype(L, Jin_Lua_Text, f); + luax_newtype(L, Jin_Lua_Text, methods); } } // namespace Lua diff --git a/src/lua/modules/graphics/je_lua_texture.cpp b/src/lua/modules/graphics/je_lua_texture.cpp index 712c4ac..5402a99 100644 --- a/src/lua/modules/graphics/je_lua_texture.cpp +++ b/src/lua/modules/graphics/je_lua_texture.cpp @@ -52,14 +52,14 @@ namespace JinEngine LUA_EXPORT void luaopen_Texture(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { "getWidth", l_getWidth }, { "getHeight", l_getHeight }, { "getSize", l_getSize }, { 0, 0 } }; - luax_newtype(L, Jin_Lua_Texture, f); + luax_newtype(L, Jin_Lua_Texture, methods); } }// namespace Lua diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp index 5bbe154..61c559b 100644 --- a/src/lua/modules/graphics/je_lua_texture_font.cpp +++ b/src/lua/modules/graphics/je_lua_texture_font.cpp @@ -45,21 +45,20 @@ namespace JinEngine Text* text = p2->getObject<Text>(); page = tf->typeset(*text, lineheight, spacing); } - Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page); Shared<Page>* shrPage = new Shared<Page>(page, Jin_Lua_Page); shrPage->setDependency((int)PageDependency::DEP_TEXTURE_FONT, &shrTexFont); - pxyPage->bind(shrPage); + Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page, shrPage); return 1; } LUA_EXPORT void luaopen_TextureFont(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { "typeset", l_typeset }, { 0, 0 } }; - luax_newtype(L, Jin_Lua_TextureFont, f); + luax_newtype(L, Jin_Lua_TextureFont, methods); } } // namespace Lua diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp index a1da345..7fea04b 100644 --- a/src/lua/modules/graphics/je_lua_ttf.cpp +++ b/src/lua/modules/graphics/je_lua_ttf.cpp @@ -45,21 +45,20 @@ namespace JinEngine Text* text = pxyText->getObject<Text>(); page = ttf->typeset(*text, lineheight, spacing); } - Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page); Shared<Page>* refPage = new Shared<Page>(page, Jin_Lua_Page); refPage->setDependency((int)PageDependency::DEP_TTF, &shrTTF); - pxyPage->bind(refPage); + Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page, refPage); return 1; } LUA_EXPORT void luaopen_TTF(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { "typeset", l_typeset }, { 0, 0 } }; - luax_newtype(L, Jin_Lua_TTF, f); + luax_newtype(L, Jin_Lua_TTF, methods); } } // namespace Lua diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp index dedf082..aa2280f 100644 --- a/src/lua/modules/graphics/je_lua_ttf_data.cpp +++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp @@ -22,11 +22,10 @@ namespace JinEngine int fontsize = luax_checkinteger(L, 2); Shared<TTFData>& shrFontData = pxyTTFData->getShared<TTFData>(); TTFData* fontData = shrFontData.getObject(); - Proxy* pxyTTF = luax_newinstance(L, Jin_Lua_TTF); TTF* font = fontData->createTTF(fontsize); Shared<TTF>* shrTTF = new Shared<TTF>(font, Jin_Lua_TTF); shrTTF->setDependency((int)TTFDependency::DEP_TTFDATA, &shrFontData); - pxyTTF->bind(shrTTF); + Proxy* pxyTTF = luax_newinstance(L, Jin_Lua_TTF, shrTTF); return 1; } @@ -39,12 +38,12 @@ namespace JinEngine LUA_EXPORT void luaopen_TTFData(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { "newTTF", l_newTTF }, { 0, 0 } }; - luax_newtype(L, Jin_Lua_TTFData, f); + luax_newtype(L, Jin_Lua_TTFData, methods); } diff --git a/src/lua/modules/joypad/je_lua_joypad.cpp b/src/lua/modules/joypad/je_lua_joypad.cpp index 8c71dc1..1261183 100644 --- a/src/lua/modules/joypad/je_lua_joypad.cpp +++ b/src/lua/modules/joypad/je_lua_joypad.cpp @@ -9,10 +9,10 @@ namespace JinEngine LUA_EXPORT int luaopen_joypad(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { 0, 0 } }; - luax_newlib(L, f); + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/math/je_lua_math.cpp b/src/lua/modules/math/je_lua_math.cpp index c163203..d12ccfa 100644 --- a/src/lua/modules/math/je_lua_math.cpp +++ b/src/lua/modules/math/je_lua_math.cpp @@ -18,11 +18,11 @@ namespace JinEngine LUA_EXPORT int luaopen_math(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "mod", l_mod }, { 0, 0 } }; - luax_newlib(L, f); + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/mouse/je_lua_mouse.cpp b/src/lua/modules/mouse/je_lua_mouse.cpp index 37677c1..44d72a2 100644 --- a/src/lua/modules/mouse/je_lua_mouse.cpp +++ b/src/lua/modules/mouse/je_lua_mouse.cpp @@ -29,12 +29,12 @@ namespace JinEngine LUA_EXPORT int luaopen_mouse(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "getPosition", l_pos }, { "setVisible", l_setVisible }, { 0, 0 } }; - luax_newlib(L, f); + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/net/je_lua_net.cpp b/src/lua/modules/net/je_lua_net.cpp index 178a93e..456bcf8 100644 --- a/src/lua/modules/net/je_lua_net.cpp +++ b/src/lua/modules/net/je_lua_net.cpp @@ -50,17 +50,15 @@ namespace Lua } } Socket* socket = new Socket(info); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket); - proxy->bind(new Shared<Socket>(socket, Jin_Lua_Socket)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket, new Shared<Socket>(socket, Jin_Lua_Socket)); return 1; } LUA_IMPLEMENT int l_Buffer(lua_State* L) { int size = luax_checkinteger(L, 1); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer); Net::Buffer* buffer = new Net::Buffer(size); - proxy->bind(new Shared<Buffer>(buffer, Jin_Lua_Buffer)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer, new Shared<Buffer>(buffer, Jin_Lua_Buffer)); return 1; } @@ -69,13 +67,13 @@ namespace Lua luaopen_Socket(L); luaopen_Buffer(L); - luaL_Reg f[] = { + luaL_Reg methods[] = { { "init", l_initNetwork }, { "newSocket", l_Socket }, { "newBuffer", l_Buffer }, { 0, 0 } }; - luax_newlib(L, f); + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/net/je_lua_socket.cpp b/src/lua/modules/net/je_lua_socket.cpp index 3af3319..94e1275 100644 --- a/src/lua/modules/net/je_lua_socket.cpp +++ b/src/lua/modules/net/je_lua_socket.cpp @@ -35,8 +35,7 @@ namespace JinEngine { SharedSocket socket = checkSocket(L); Socket* client = socket->accept(); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket); - proxy->bind(new Shared<Socket>(client, Jin_Lua_Socket)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket, new Shared<Socket>(client, Jin_Lua_Socket)); return 1; } @@ -46,9 +45,8 @@ namespace JinEngine SharedSocket socket = checkSocket(L); char buffer[BUFFER_SIZE] = {0}; int size = socket->receive(buffer, BUFFER_SIZE); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer); Net::Buffer* netBuffer = new Net::Buffer(buffer, size); - proxy->bind(new Shared<Buffer>(netBuffer, Jin_Lua_Buffer)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer, new Shared<Buffer>(netBuffer, Jin_Lua_Buffer)); return 1; } @@ -61,8 +59,7 @@ namespace JinEngine char buffer[BUFFER_SIZE]; int size = socket->receiveFrom(buffer, BUFFER_SIZE, address, port); Net::Buffer* netBuffer = new Net::Buffer(buffer, size); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer); - proxy->bind(new Shared<Buffer>(netBuffer, Jin_Lua_Buffer)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer, new Shared<Buffer>(netBuffer, Jin_Lua_Buffer)); return 1; } diff --git a/src/lua/modules/thread/je_lua_thread.cpp b/src/lua/modules/thread/je_lua_thread.cpp index 070e9ac..2444e7b 100644 --- a/src/lua/modules/thread/je_lua_thread.cpp +++ b/src/lua/modules/thread/je_lua_thread.cpp @@ -29,8 +29,7 @@ namespace JinEngine luax_openlibs(L); luaopen_jin(L); luax_getglobal(L, MODULE_NAME); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread); - proxy->bind(&shared); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread, &shared); luax_setfield(L, -2, "_curThread"); luax_dostring(L, shared->code.c_str()); luax_close(L); @@ -126,8 +125,7 @@ namespace JinEngine case Thread::Variant::POINTER: Proxy* p = (Proxy*)v.pointer; - Proxy* proxy = luax_newinstance(L, p->getObjectType()); - proxy->bind(p->shared); + Proxy* proxy = luax_newinstance(L, p->getObjectType(), p->shared); break; } @@ -160,8 +158,7 @@ namespace JinEngine case Thread::Variant::POINTER: Proxy* p = (Proxy*)v.pointer; const char* objType = p->getObjectType(); - Proxy* proxy = luax_newinstance(L, objType); - proxy->bind(p->shared); + Proxy* proxy = luax_newinstance(L, objType, p->shared); break; } @@ -217,9 +214,8 @@ namespace JinEngine { const char* name = luax_checkstring(L, 1); const char* code = luax_checkstring(L, 2); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread); Thread* thread = new Thread(name, code, threadRunner); - proxy->bind(new Shared<Thread>(thread, Jin_Lua_Thread)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread, new Shared<Thread>(thread, Jin_Lua_Thread)); return 1; } @@ -234,12 +230,12 @@ namespace JinEngine { luaopen_Thread(L); - luaL_Reg f[] = { + luaL_Reg methods[] = { { "newThread", l_newThread }, { "getThread", l_getThread }, { 0, 0 } }; - luax_newlib(L, f); + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/time/je_lua_time.cpp b/src/lua/modules/time/je_lua_time.cpp index 626d843..6ad4935 100644 --- a/src/lua/modules/time/je_lua_time.cpp +++ b/src/lua/modules/time/je_lua_time.cpp @@ -34,8 +34,7 @@ namespace JinEngine LUA_IMPLEMENT int l_newTimer(lua_State* L) { - Proxy* proxy = luax_newinstance(L, Jin_Lua_Timer); - proxy->bind(new Shared<Timer>(new Timer(), Jin_Lua_Timer)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Timer, new Shared<Timer>(new Timer(), Jin_Lua_Timer)); return 1; } @@ -55,7 +54,7 @@ namespace JinEngine LUA_EXPORT int luaopen_time(lua_State* L) { luaopen_Timer(L); - luaL_Reg f[] = { + luaL_Reg methods[] = { { "second", l_sec }, { "sleep", l_sleep }, { "newTimer", l_newTimer }, @@ -63,7 +62,7 @@ namespace JinEngine { "getDelta", l_getDelta }, { 0, 0 }, }; - luax_newlib(L, f); + luax_newlib(L, methods); return 1; } diff --git a/src/lua/modules/time/je_lua_timer.cpp b/src/lua/modules/time/je_lua_timer.cpp index 281f3c2..6dc6798 100644 --- a/src/lua/modules/time/je_lua_timer.cpp +++ b/src/lua/modules/time/je_lua_timer.cpp @@ -46,10 +46,9 @@ namespace JinEngine for(int i = 4; i <= n; ++i) func->pushParam(i); Timer::Handler* handler = timer->every(s, timerCallback, func, finishCallback); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler); Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler); shrHandler->retain(); - proxy->bind(shrHandler); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler, shrHandler); return 1; } @@ -65,10 +64,9 @@ namespace JinEngine for (int i = 4; i <= n; ++i) func->pushParam(i); Timer::Handler* handler = timer->after(s, timerCallback, func, finishCallback); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler); Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler); shrHandler->retain(); - proxy->bind(shrHandler); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler, shrHandler); return 1; } @@ -85,10 +83,9 @@ namespace JinEngine for (int i = 5; i <= n; ++i) func->pushParam(i); Timer::Handler* handler = timer->repeat(s, count, timerCallback, func, finishCallback); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler); Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler); shrHandler->retain(); - proxy->bind(shrHandler); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler, shrHandler); return 1; } @@ -128,7 +125,7 @@ namespace JinEngine LUA_EXPORT void luaopen_Timer(lua_State* L) { - luaL_Reg f[] = { + luaL_Reg methods[] = { { "__gc", l_gc }, { "every", l_every }, { "after", l_after }, @@ -139,7 +136,7 @@ namespace JinEngine { 0, 0 } }; - luax_newtype(L, Jin_Lua_Timer, f); + luax_newtype(L, Jin_Lua_Timer, methods); } } |