diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jin/main.cpp | 14 | ||||
-rw-r--r-- | src/lua/common/je_lua.cpp | 16 | ||||
-rw-r--r-- | src/lua/common/je_lua.h | 15 | ||||
-rw-r--r-- | src/lua/common/je_lua_proxy.cpp | 32 | ||||
-rw-r--r-- | src/lua/common/je_lua_proxy.h | 27 | ||||
-rw-r--r-- | src/lua/common/je_lua_shared.cpp | 94 | ||||
-rw-r--r-- | src/lua/common/je_lua_shared.hpp | 98 | ||||
-rw-r--r-- | src/lua/jin.cpp | 24 | ||||
-rw-r--r-- | src/lua/jin.h | 4 | ||||
-rw-r--r-- | src/lua/modules/audio/je_lua_audio.cpp | 2 | ||||
-rw-r--r-- | src/lua/modules/graphics/je_lua_bitmap.cpp | 2 | ||||
-rw-r--r-- | src/lua/modules/graphics/je_lua_graphics.cpp | 30 | ||||
-rw-r--r-- | src/lua/modules/graphics/je_lua_spritesheet.cpp | 4 | ||||
-rw-r--r-- | src/lua/modules/graphics/je_lua_texture_font.cpp | 2 | ||||
-rw-r--r-- | src/lua/modules/graphics/je_lua_ttf.cpp | 2 | ||||
-rw-r--r-- | src/lua/modules/graphics/je_lua_ttf_data.cpp | 2 | ||||
-rw-r--r-- | src/lua/modules/net/je_lua_net.cpp | 4 | ||||
-rw-r--r-- | src/lua/modules/net/je_lua_socket.cpp | 6 | ||||
-rw-r--r-- | src/lua/modules/thread/je_lua_thread.cpp | 4 | ||||
-rw-r--r-- | src/lua/modules/time/je_lua_time.cpp | 2 | ||||
-rw-r--r-- | src/lua/modules/time/je_lua_timer.cpp | 6 |
21 files changed, 213 insertions, 177 deletions
diff --git a/src/jin/main.cpp b/src/jin/main.cpp index fb3876b..31e837f 100644 --- a/src/jin/main.cpp +++ b/src/jin/main.cpp @@ -13,32 +13,24 @@ using namespace std; using namespace JinEngine::Filesystem; -using namespace JinEngine::Lua; // Load game under cwd. static void load(const char* cwd) { - // Global lua runtime. lua_State* L = luax_newstate(); // Open lua standard module. luax_openlibs(L); + // Open jin module. - luaopen_jin(L); - // Set current working directory. - luax_newtable(L); - luax_setfieldstring(L, "cwd", cwd); - luax_setfield(L, -2, "args"); - // Clear lua stack. - luax_clearstack(L); + JinEngine::Lua::open(L); // Boot jin and run it. - boot(L); + JinEngine::Lua::boot(L, cwd); // Close lua lib. luax_close(L); - } #ifdef _WIN32 diff --git a/src/lua/common/je_lua.cpp b/src/lua/common/je_lua.cpp index 2011e15..ad3f756 100644 --- a/src/lua/common/je_lua.cpp +++ b/src/lua/common/je_lua.cpp @@ -1,22 +1,14 @@ +#include "libjin/jin.h" + #include "je_lua.h" +using namespace JinEngine::Math; + namespace JinEngine { namespace Lua { - lua_State * LuaState::mL = nullptr; - - void LuaState::set(lua_State* L) - { - mL = L; - } - - lua_State* LuaState::get() - { - return mL; - } - /// /// Lua objects table. Map object to proxy, like objects_table[object] = proxy. /// diff --git a/src/lua/common/je_lua.h b/src/lua/common/je_lua.h index 753230e..56a5090 100644 --- a/src/lua/common/je_lua.h +++ b/src/lua/common/je_lua.h @@ -1,5 +1,8 @@ #ifndef __JE_LUA_H__ #define __JE_LUA_H__ + +#include <vector> + #include "LuaJIT/lua.hpp" #include "libraries/luax/luax.h" @@ -12,18 +15,6 @@ namespace JinEngine namespace Lua { - // Lua state singleton. - class LuaState - { - public: - static lua_State * get(); - static void set(lua_State* L); - - private: - static lua_State * mL; - - }; - /// /// /// diff --git a/src/lua/common/je_lua_proxy.cpp b/src/lua/common/je_lua_proxy.cpp new file mode 100644 index 0000000..dc6df30 --- /dev/null +++ b/src/lua/common/je_lua_proxy.cpp @@ -0,0 +1,32 @@ +#include "je_lua.h" +#include "je_lua_proxy.h" + +namespace JinEngine +{ + namespace Lua + { + + void Proxy::bind(SharedBase* s) + { + if (s == nullptr) + return; + shared = s; + shared->retain(); + } + + void Proxy::release() + { + if (shared != nullptr) + { + shared->release(); + shared = nullptr; + } + } + + const char* Proxy::getObjectType() + { + return shared->type; + } + + } +}
\ No newline at end of file diff --git a/src/lua/common/je_lua_proxy.h b/src/lua/common/je_lua_proxy.h index d6a6a0a..aa03fa0 100644 --- a/src/lua/common/je_lua_proxy.h +++ b/src/lua/common/je_lua_proxy.h @@ -3,6 +3,8 @@ #include "je_lua_shared.hpp" +struct lua_State; + namespace JinEngine { namespace Lua @@ -11,22 +13,12 @@ namespace JinEngine class Proxy { public: - void bind(SharedBase* s) - { - if (s == nullptr) - return; - shared = s; - shared->retain(); - } + /// + /// Set lua_State and object it bind. + /// + void bind(SharedBase* s); - void release() - { - if (shared != nullptr) - { - shared->release(); - shared = nullptr; - } - } + void release(); template<class T> Shared<T>& getShared() @@ -44,10 +36,7 @@ namespace JinEngine return shared.getObject(); } - const char* getObjectType() - { - return shared->type; - } + const char* getObjectType(); // Bind shared object. SharedBase* shared; diff --git a/src/lua/common/je_lua_shared.cpp b/src/lua/common/je_lua_shared.cpp new file mode 100644 index 0000000..a3478dd --- /dev/null +++ b/src/lua/common/je_lua_shared.cpp @@ -0,0 +1,94 @@ +#include "je_lua.h" +#include "je_lua_shared.hpp" + +namespace JinEngine +{ + namespace Lua + { + + void SharedBase::retain() + { + ++mCount; + } + + void SharedBase::release() + { + if (--mCount <= 0) + { + luax_removeobject(mL, this); + delete this; + } + } + + void SharedBase::setDependency(int key, SharedBase* shared) + { + removeDependency(key); + shared->retain(); + mDependencies.insert(std::pair<int, SharedBase*>(key, shared)); + } + + void SharedBase::removeDependency(int key) + { + if (!isDependOn(key)) + return; + std::map<int, SharedBase*>::iterator it = mDependencies.find(key); + it->second->release(); + mDependencies.erase(it); + } + + void SharedBase::removeDependency(SharedBase* dep) + { + for (std::map<int, SharedBase*>::iterator it = mDependencies.begin(); it != mDependencies.end();) + { + if (it->second == dep) + { + it->second->release(); + mDependencies.erase(it); + } + else + ++it; + } + } + + bool SharedBase::isDependOn(int key) + { + return mDependencies.find(key) != mDependencies.end(); + } + + bool SharedBase::isDependOn(SharedBase* shared) + { + for (std::pair<int, SharedBase*> dep : mDependencies) + { + if (dep.second == shared) + return true; + } + return false; + } + + void SharedBase::clearDependencies() + { + for (std::pair<int, SharedBase*> dep : mDependencies) + dep.second->release(); + mDependencies.clear(); + } + + SharedBase* SharedBase::getDependency(int key) + { + if (!isDependOn(key)) + return nullptr; + return mDependencies.find(key)->second; + } + + bool SharedBase::isType(const char* t) + { + return strcmp(type, t) == 0; + } + + int SharedBase::getDependencyCount() + { + return mDependencies.size(); + } + + + } +}
\ No newline at end of file diff --git a/src/lua/common/je_lua_shared.hpp b/src/lua/common/je_lua_shared.hpp index 59e945d..2f1e18b 100644 --- a/src/lua/common/je_lua_shared.hpp +++ b/src/lua/common/je_lua_shared.hpp @@ -5,6 +5,9 @@ #include <map> #include <vector> +#include <functional> + +struct lua_State; namespace JinEngine { @@ -14,96 +17,37 @@ namespace JinEngine class SharedBase { public: - void retain() - { - ++mCount; - } + void retain(); - void release() - { - if (--mCount <= 0) - delete this; - } + void release(); // Object type. const char* const type; - void setDependency(int key, SharedBase* shared) - { - removeDependency(key); - shared->retain(); - mDependencies.insert(std::pair<int, SharedBase*>(key, shared)); - } + void setDependency(int key, SharedBase* shared); - void removeDependency(int key) - { - if (!isDependOn(key)) - return; - DepMap::iterator it = mDependencies.find(key); - it->second->release(); - mDependencies.erase(it); - } + void removeDependency(int key); - void removeDependency(SharedBase* dep) - { - for (DepMap::iterator it = mDependencies.begin(); it != mDependencies.end();) - { - if (it->second == dep) - { - it->second->release(); - mDependencies.erase(it); - } - else - ++it; - } - } + void removeDependency(SharedBase* dep); - bool isDependOn(int key) - { - return mDependencies.find(key) != mDependencies.end(); - } + bool isDependOn(int key); - bool isDependOn(SharedBase* shared) - { - for (std::pair<int, SharedBase*> dep : mDependencies) - { - if (dep.second == shared) - return true; - } - return false; - } + bool isDependOn(SharedBase* shared); - void clearDependencies() - { - for (std::pair<int, SharedBase*> dep : mDependencies) - dep.second->release(); - mDependencies.clear(); - } + void clearDependencies(); - SharedBase* getDependency(int key) - { - if (!isDependOn(key)) - return nullptr; - return mDependencies.find(key)->second; - } + SharedBase* getDependency(int key); - bool isType(const char* t) - { - return strcmp(type, t) == 0; - } + bool isType(const char* t); - int getDependencyCount() - { - return mDependencies.size(); - } + int getDependencyCount(); protected: - using DepMap = std::map<int, SharedBase*>; - - SharedBase(void* obj, const char* t) + SharedBase(lua_State* L, void* obj, const char* t) : mCount(0) , mObject(obj) + , mL(L) , type(t) { } @@ -117,15 +61,16 @@ namespace JinEngine void* mObject; int mCount; - DepMap mDependencies; + lua_State* mL; + std::map<int, SharedBase*> mDependencies; }; template<class T> class Shared : public SharedBase { public: - Shared(T* obj, const char* type) - : SharedBase(obj, type) + Shared(lua_State* L, T* obj, const char* type) + : SharedBase(L, obj, type) { } @@ -146,9 +91,6 @@ namespace JinEngine // Make shared only be able created with new. ~Shared() { - // Delete object mapping. - luax_removeobject(LuaState::get(), this); - // T* obj = static_cast<T*>(mObject); delete obj; } diff --git a/src/lua/jin.cpp b/src/lua/jin.cpp index 39291ac..87e7bac 100644 --- a/src/lua/jin.cpp +++ b/src/lua/jin.cpp @@ -53,10 +53,10 @@ namespace JinEngine } LUA_IMPLEMENT const luax_Str s[] = { - { "version", VERSION }, - { "author", AUTHOR }, - { "codename", CODE_NAME }, - { 0, 0 } + { "version", VERSION }, + { "author", AUTHOR }, + { "codename", CODE_NAME }, + { 0, 0 } }; LUA_IMPLEMENT const luax_Num n[] = { @@ -64,11 +64,9 @@ namespace JinEngine { 0, 0 } }; - /* register jin module, keep it on the top of stack */ - LUA_EXPORT int luaopen_jin(lua_State* L) + // Register jin module, keep it on the top of stack. + LUA_EXPORT void open(lua_State* L) { - LuaState::set(L); - luax_globaltable(L, MODULE_NAME); // Register values. @@ -100,11 +98,17 @@ namespace JinEngine luax_setfield(L, -2, modules[i].name); } - return 1; + // Pop jin table. + luax_pop(L, 1); } - LUA_EXPORT void boot(lua_State* L) + 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"); + luax_clearstack(L); JinEngine::Embed::boot(L); } diff --git a/src/lua/jin.h b/src/lua/jin.h index 473ead7..7b38ce7 100644 --- a/src/lua/jin.h +++ b/src/lua/jin.h @@ -23,12 +23,12 @@ namespace JinEngine /// /// open jin module. /// - LUA_EXPORT int luaopen_jin(lua_State* L); + LUA_EXPORT void open(lua_State* L); /// /// Boot jin. /// - LUA_EXPORT void boot(lua_State* L); + LUA_EXPORT void boot(lua_State* L, const char* cwd); } // namespace JinEngine } // namespace Lua diff --git a/src/lua/modules/audio/je_lua_audio.cpp b/src/lua/modules/audio/je_lua_audio.cpp index 61b9556..57500eb 100644 --- a/src/lua/modules/audio/je_lua_audio.cpp +++ b/src/lua/modules/audio/je_lua_audio.cpp @@ -97,7 +97,7 @@ namespace JinEngine luax_pushnil(L); return 1; } - Proxy* proxy = luax_newinstance(L, Jin_Lua_Source, new Shared<Source>(src, Jin_Lua_Source)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Source, new Shared<Source>(L, src, Jin_Lua_Source)); return 1; } diff --git a/src/lua/modules/graphics/je_lua_bitmap.cpp b/src/lua/modules/graphics/je_lua_bitmap.cpp index 2495fb3..056ed70 100644 --- a/src/lua/modules/graphics/je_lua_bitmap.cpp +++ b/src/lua/modules/graphics/je_lua_bitmap.cpp @@ -90,7 +90,7 @@ namespace JinEngine SharedBitmap shared = checkBitmap(L); Bitmap* bitmap = shared.getObject(); Bitmap* b = Bitmap::clone(bitmap); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap, new Shared<Bitmap>(b, Jin_Lua_Bitmap)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap, new Shared<Bitmap>(L, b, Jin_Lua_Bitmap)); return 1; } diff --git a/src/lua/modules/graphics/je_lua_graphics.cpp b/src/lua/modules/graphics/je_lua_graphics.cpp index 82793be..36829ab 100644 --- a/src/lua/modules/graphics/je_lua_graphics.cpp +++ b/src/lua/modules/graphics/je_lua_graphics.cpp @@ -207,7 +207,7 @@ namespace JinEngine return 1; } } - Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap, new Shared<Bitmap>(bitmap, Jin_Lua_Bitmap)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Bitmap, new Shared<Bitmap>(L, bitmap, Jin_Lua_Bitmap)); return 1; } @@ -227,7 +227,7 @@ namespace JinEngine const char* path = luax_checkstring(L, 1); texture = Texture::createTexture(path); } - Proxy* proxy = luax_newinstance(L, Jin_Lua_Texture, new Shared<Texture>(texture, Jin_Lua_Texture)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Texture, new Shared<Texture>(L, texture, Jin_Lua_Texture)); return 1; } @@ -241,7 +241,7 @@ namespace JinEngine luax_pushnil(L); return 1; } - Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader, new Shared<Shader>(jsl, Jin_Lua_Shader)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader, new Shared<Shader>(L, jsl, Jin_Lua_Shader)); return 1; } @@ -264,7 +264,7 @@ namespace JinEngine luax_pushnil(L); return 1; } - Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader, new Shared<Shader>(jsl, Jin_Lua_Shader)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Shader, new Shared<Shader>(L, jsl, Jin_Lua_Shader)); return 1; } @@ -273,7 +273,7 @@ namespace JinEngine int w = luax_checknumber(L, 1); int h = luax_checknumber(L, 2); Canvas* cvs = Canvas::createCanvas(w, h); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Canvas, new Shared<Canvas>(cvs, Jin_Lua_Canvas)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Canvas, new Shared<Canvas>(L, cvs, Jin_Lua_Canvas)); return 1; } @@ -684,7 +684,7 @@ namespace JinEngine fs->read(path, b); fd = TTFData::createTTFData(&b, b.size()); } - Proxy* proxy = luax_newinstance(L, Jin_Lua_TTFData, new Shared<TTFData>(fd, Jin_Lua_TTFData)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_TTFData, new Shared<TTFData>(L, fd, Jin_Lua_TTFData)); return 1; } @@ -707,7 +707,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, new Shared<Text>(text, Jin_Lua_Text)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Text, new Shared<Text>(L, text, Jin_Lua_Text)); return 1; } @@ -735,7 +735,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, new Shared<Sprite>(new Sprite(graphic, quad, origin), Jin_Lua_Sprite)); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(L, new Sprite(graphic, quad, origin), Jin_Lua_Sprite)); } else if (n == 4) { @@ -746,19 +746,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, new Shared<Sprite>(new Sprite(graphic, quad, ox, oy), Jin_Lua_Sprite)); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(L, 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, new Shared<Sprite>(new Sprite(graphic, origin), Jin_Lua_Sprite)); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(L, 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, new Shared<Sprite>(new Sprite(graphic, ox, oy), Jin_Lua_Sprite)); + Proxy* p = luax_newinstance(L, Jin_Lua_Sprite, new Shared<Sprite>(L, new Sprite(graphic, ox, oy), Jin_Lua_Sprite)); } else { @@ -780,7 +780,7 @@ namespace JinEngine if (pxyGraphic != nullptr) { Graphic* graphic = pxyGraphic->getObject<Graphic>(); - Shared<SpriteSheet>* shrSSheet = new Shared<SpriteSheet>(new SpriteSheet(graphic), Jin_Lua_SpriteSheet); + Shared<SpriteSheet>* shrSSheet = new Shared<SpriteSheet>(L, new SpriteSheet(graphic), Jin_Lua_SpriteSheet); Shared<Graphic>& shrGraphic = pxyGraphic->getShared<Graphic>(); shrSSheet->setDependency((int)SpriteSheetDependency::DEP_GRAPHIC, &shrGraphic); Proxy* pxySSheet = luax_newinstance(L, Jin_Lua_SpriteSheet, shrSSheet); @@ -794,7 +794,7 @@ namespace JinEngine LUA_IMPLEMENT int l_newAnimation(lua_State* L) { int argc = luax_gettop(L); - Shared<Animation>* shrAnimation = new Shared<Animation>(new Animation(), Jin_Lua_Animation); + Shared<Animation>* shrAnimation = new Shared<Animation>(L, new Animation(), Jin_Lua_Animation); if (argc >= 3) { if (!luax_istable(L, 1)) @@ -825,7 +825,7 @@ namespace JinEngine LUA_IMPLEMENT int l_newAnimator(lua_State* L) { int argc = luax_gettop(L); - Shared<Animator>* shrAniamtor = new Shared<Animator>(new Animator(), Jin_Lua_Animator); + Shared<Animator>* shrAniamtor = new Shared<Animator>(L, new Animator(), Jin_Lua_Animator); if (argc >= 1) { Proxy* pxyAnimation = (Proxy*)luax_checktype(L, 1, Jin_Lua_Animation); @@ -884,7 +884,7 @@ namespace JinEngine // Delete temporary text. delete text; } - Proxy* proxy = luax_newinstance(L, Jin_Lua_TextureFont, new Shared<TextureFont>(textureFont, Jin_Lua_TextureFont)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_TextureFont, new Shared<TextureFont>(L, textureFont, Jin_Lua_TextureFont)); return 1; } diff --git a/src/lua/modules/graphics/je_lua_spritesheet.cpp b/src/lua/modules/graphics/je_lua_spritesheet.cpp index 362a78d..3f22319 100644 --- a/src/lua/modules/graphics/je_lua_spritesheet.cpp +++ b/src/lua/modules/graphics/je_lua_spritesheet.cpp @@ -48,7 +48,7 @@ namespace JinEngine origin = static_cast<Origin>(o); spr = sheet->createSprite(quad, origin); } - Shared<Sprite>* shrSprite = new Shared<Sprite>(spr, Jin_Lua_Sprite); + Shared<Sprite>* shrSprite = new Shared<Sprite>(L, spr, Jin_Lua_Sprite); shrSprite->setDependency((int)SpriteDependency::DEP_SPRITESHEET, &shrSSheet); Proxy* pxySprite = luax_newinstance(L, Jin_Lua_Sprite, shrSprite); return 1; @@ -97,7 +97,7 @@ namespace JinEngine for (int i = 0; i < sprs.size(); ++i) { Sprite* spr = sprs[i]; - Shared<Sprite>* shrSpr = new Shared<Sprite>(spr, Jin_Lua_Sprite); + Shared<Sprite>* shrSpr = new Shared<Sprite>(L, spr, Jin_Lua_Sprite); shrSpr->setDependency((int)SpriteDependency::DEP_GRAPHIC, shrGraphic); Proxy* pxys = (Proxy*)luax_newinstance(L, Jin_Lua_Sprite, shrSpr); luax_rawseti(L, -2, i + 1); diff --git a/src/lua/modules/graphics/je_lua_texture_font.cpp b/src/lua/modules/graphics/je_lua_texture_font.cpp index 6c62ee2..58677eb 100644 --- a/src/lua/modules/graphics/je_lua_texture_font.cpp +++ b/src/lua/modules/graphics/je_lua_texture_font.cpp @@ -44,7 +44,7 @@ namespace JinEngine Text* text = p2->getObject<Text>(); page = tf->typeset(*text, lineheight, spacing); } - Shared<Page>* shrPage = new Shared<Page>(page, Jin_Lua_Page); + Shared<Page>* shrPage = new Shared<Page>(L, page, Jin_Lua_Page); shrPage->setDependency((int)PageDependency::DEP_TEXTURE_FONT, &shrTexFont); Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page, shrPage); return 1; diff --git a/src/lua/modules/graphics/je_lua_ttf.cpp b/src/lua/modules/graphics/je_lua_ttf.cpp index fb4b0df..c3d9aae 100644 --- a/src/lua/modules/graphics/je_lua_ttf.cpp +++ b/src/lua/modules/graphics/je_lua_ttf.cpp @@ -44,7 +44,7 @@ namespace JinEngine Text* text = pxyText->getObject<Text>(); page = ttf->typeset(*text, lineheight, spacing); } - Shared<Page>* refPage = new Shared<Page>(page, Jin_Lua_Page); + Shared<Page>* refPage = new Shared<Page>(L, page, Jin_Lua_Page); refPage->setDependency((int)PageDependency::DEP_TTF, &shrTTF); Proxy* pxyPage = luax_newinstance(L, Jin_Lua_Page, refPage); return 1; diff --git a/src/lua/modules/graphics/je_lua_ttf_data.cpp b/src/lua/modules/graphics/je_lua_ttf_data.cpp index 8042d69..7fcadcd 100644 --- a/src/lua/modules/graphics/je_lua_ttf_data.cpp +++ b/src/lua/modules/graphics/je_lua_ttf_data.cpp @@ -22,7 +22,7 @@ namespace JinEngine Shared<TTFData>& shrFontData = pxyTTFData->getShared<TTFData>(); TTFData* fontData = shrFontData.getObject(); TTF* font = fontData->createTTF(fontsize); - Shared<TTF>* shrTTF = new Shared<TTF>(font, Jin_Lua_TTF); + Shared<TTF>* shrTTF = new Shared<TTF>(L, font, Jin_Lua_TTF); shrTTF->setDependency((int)TTFDependency::DEP_TTFDATA, &shrFontData); Proxy* pxyTTF = luax_newinstance(L, Jin_Lua_TTF, shrTTF); return 1; diff --git a/src/lua/modules/net/je_lua_net.cpp b/src/lua/modules/net/je_lua_net.cpp index 4b5513a..058b4e8 100644 --- a/src/lua/modules/net/je_lua_net.cpp +++ b/src/lua/modules/net/je_lua_net.cpp @@ -49,7 +49,7 @@ namespace Lua } } Socket* socket = new Socket(info); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket, new Shared<Socket>(socket, Jin_Lua_Socket)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket, new Shared<Socket>(L, socket, Jin_Lua_Socket)); return 1; } @@ -57,7 +57,7 @@ namespace Lua { int size = luax_checkinteger(L, 1); Net::Buffer* buffer = new Net::Buffer(size); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer, new Shared<Buffer>(buffer, Jin_Lua_Buffer)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer, new Shared<Buffer>(L, buffer, Jin_Lua_Buffer)); return 1; } diff --git a/src/lua/modules/net/je_lua_socket.cpp b/src/lua/modules/net/je_lua_socket.cpp index 3eed91f..899c70a 100644 --- a/src/lua/modules/net/je_lua_socket.cpp +++ b/src/lua/modules/net/je_lua_socket.cpp @@ -34,7 +34,7 @@ namespace JinEngine { SharedSocket socket = checkSocket(L); Socket* client = socket->accept(); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket, new Shared<Socket>(client, Jin_Lua_Socket)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Socket, new Shared<Socket>(L, client, Jin_Lua_Socket)); return 1; } @@ -45,7 +45,7 @@ namespace JinEngine char buffer[BUFFER_SIZE] = {0}; int size = socket->receive(buffer, BUFFER_SIZE); Net::Buffer* netBuffer = new Net::Buffer(buffer, size); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer, new Shared<Buffer>(netBuffer, Jin_Lua_Buffer)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer, new Shared<Buffer>(L, netBuffer, Jin_Lua_Buffer)); return 1; } @@ -58,7 +58,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, new Shared<Buffer>(netBuffer, Jin_Lua_Buffer)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Buffer, new Shared<Buffer>(L, 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 2444e7b..4e0442e 100644 --- a/src/lua/modules/thread/je_lua_thread.cpp +++ b/src/lua/modules/thread/je_lua_thread.cpp @@ -27,7 +27,7 @@ namespace JinEngine SharedThread shared = *(Shared<Thread>*)t; lua_State* L = lua_open(); luax_openlibs(L); - luaopen_jin(L); + open(L); luax_getglobal(L, MODULE_NAME); Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread, &shared); luax_setfield(L, -2, "_curThread"); @@ -215,7 +215,7 @@ namespace JinEngine const char* name = luax_checkstring(L, 1); const char* code = luax_checkstring(L, 2); Thread* thread = new Thread(name, code, threadRunner); - Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread, new Shared<Thread>(thread, Jin_Lua_Thread)); + Proxy* proxy = luax_newinstance(L, Jin_Lua_Thread, new Shared<Thread>(L, thread, Jin_Lua_Thread)); return 1; } diff --git a/src/lua/modules/time/je_lua_time.cpp b/src/lua/modules/time/je_lua_time.cpp index 4eb579f..54ab798 100644 --- a/src/lua/modules/time/je_lua_time.cpp +++ b/src/lua/modules/time/je_lua_time.cpp @@ -33,7 +33,7 @@ namespace JinEngine LUA_IMPLEMENT int l_newTimer(lua_State* L) { - Shared<Timer>* shrTimer = new Shared<Timer>(new Timer(), Jin_Lua_Timer); + Shared<Timer>* shrTimer = new Shared<Timer>(L, new Timer(), Jin_Lua_Timer); luax_newinstance(L, Jin_Lua_Timer, shrTimer); return 1; } diff --git a/src/lua/modules/time/je_lua_timer.cpp b/src/lua/modules/time/je_lua_timer.cpp index ccb902a..570e537 100644 --- a/src/lua/modules/time/je_lua_timer.cpp +++ b/src/lua/modules/time/je_lua_timer.cpp @@ -44,7 +44,7 @@ namespace JinEngine for(int i = 4; i <= n; ++i) func->pushParam(i); Timer::Handler* handler = shared->every(s, timerCallback, func, finishCallback); - Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler); + Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(L, handler, Jin_Lua_Handler); Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler, shrHandler); return 1; } @@ -60,7 +60,7 @@ namespace JinEngine for (int i = 4; i <= n; ++i) func->pushParam(i); Timer::Handler* handler = shared->after(s, timerCallback, func, finishCallback); - Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler); + Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(L, handler, Jin_Lua_Handler); Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler, shrHandler); return 1; } @@ -77,7 +77,7 @@ namespace JinEngine for (int i = 5; i <= n; ++i) func->pushParam(i); Timer::Handler* handler = shared->repeat(s, count, timerCallback, func, finishCallback); - Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(handler, Jin_Lua_Handler); + Shared<Timer::Handler>* shrHandler = new Shared<Timer::Handler>(L, handler, Jin_Lua_Handler); Proxy* proxy = luax_newinstance(L, Jin_Lua_Handler, shrHandler); return 1; } |