diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/audio/luaopen_audio.cpp | 3 | ||||
-rw-r--r-- | src/lua/common/Reference.hpp | 1 | ||||
-rw-r--r-- | src/lua/common/constant.h | 1 | ||||
-rw-r--r-- | src/lua/graphics/luaopen_graphics.cpp | 3 | ||||
-rw-r--r-- | src/lua/luaopen_jin.h | 4 | ||||
-rw-r--r-- | src/lua/net/luaopen_net.cpp | 6 | ||||
-rw-r--r-- | src/lua/thread/luaopen_Thread.cpp | 7 | ||||
-rw-r--r-- | src/lua/thread/luaopen_thread.cpp | 7 | ||||
-rw-r--r-- | src/main.cpp | 20 |
9 files changed, 18 insertions, 34 deletions
diff --git a/src/lua/audio/luaopen_audio.cpp b/src/lua/audio/luaopen_audio.cpp index e6c54c9..40bfb04 100644 --- a/src/lua/audio/luaopen_audio.cpp +++ b/src/lua/audio/luaopen_audio.cpp @@ -72,8 +72,7 @@ namespace lua fs->read(f, &b); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_AUDIO_SOURCE, sizeof(Proxy)); Source* src = Source::createSource(b.data, b.size); - Ref<Source>* ref = new Ref<Source>(src); - proxy->bind(ref, JIN_AUDIO_SOURCE); + proxy->bind(new Ref<Source>(src), JIN_AUDIO_SOURCE); return 1; } diff --git a/src/lua/common/Reference.hpp b/src/lua/common/Reference.hpp index f330323..7647a3f 100644 --- a/src/lua/common/Reference.hpp +++ b/src/lua/common/Reference.hpp @@ -26,6 +26,7 @@ namespace lua , object(obj) { } + Reference(const Reference&); virtual ~Reference() { diff --git a/src/lua/common/constant.h b/src/lua/common/constant.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/src/lua/common/constant.h @@ -0,0 +1 @@ +#pragma once diff --git a/src/lua/graphics/luaopen_graphics.cpp b/src/lua/graphics/luaopen_graphics.cpp index c30365f..4a5ccce 100644 --- a/src/lua/graphics/luaopen_graphics.cpp +++ b/src/lua/graphics/luaopen_graphics.cpp @@ -407,8 +407,7 @@ namespace lua fs->read(path, &b); font->loadb((const unsigned char*)b.data); } - Ref<Font>* ref = new Ref<Font>(font); - proxy->bind(ref, JIN_GRAPHICS_FONT); + proxy->bind(new Ref<Font>(font), JIN_GRAPHICS_FONT); return 1; } diff --git a/src/lua/luaopen_jin.h b/src/lua/luaopen_jin.h index c93b66d..9cceb9e 100644 --- a/src/lua/luaopen_jin.h +++ b/src/lua/luaopen_jin.h @@ -33,11 +33,7 @@ namespace jin namespace lua { - /** - * open jin lib and boot - */ int luaopen_jin(lua_State* L); - void boot(lua_State* L); } // jin diff --git a/src/lua/net/luaopen_net.cpp b/src/lua/net/luaopen_net.cpp index 5a9ce71..a3f7900 100644 --- a/src/lua/net/luaopen_net.cpp +++ b/src/lua/net/luaopen_net.cpp @@ -47,9 +47,8 @@ namespace lua } } Socket* socket = new Socket(info); - Ref<Socket>* ref = new Ref<Socket>(socket); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_SOCKET, sizeof(Proxy)); - proxy->bind(ref, JIN_NETWORK_SOCKET); + proxy->bind(new Ref<Socket>(socket), JIN_NETWORK_SOCKET); return 1; } @@ -59,8 +58,7 @@ namespace lua int size = luax_checkinteger(L, 1); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_NETWORK_BUFFER, sizeof(Proxy)); net::Buffer* buffer = new net::Buffer(size); - Ref<Buffer>* ref = new Ref<Buffer>(buffer); - proxy->bind(ref, JIN_NETWORK_BUFFER); + proxy->bind(new Ref<Buffer>(buffer), JIN_NETWORK_BUFFER); return 1; } diff --git a/src/lua/thread/luaopen_Thread.cpp b/src/lua/thread/luaopen_Thread.cpp index eaa263d..5d44c30 100644 --- a/src/lua/thread/luaopen_Thread.cpp +++ b/src/lua/thread/luaopen_Thread.cpp @@ -219,8 +219,7 @@ namespace lua const char* code = luax_checkstring(L, 2); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_THREAD_THREAD, sizeof(Proxy)); Thread* thread = new Thread(name, code, threadRunner); - Ref<Thread>* ref = new Ref<Thread>(thread); - proxy->bind(ref, JIN_THREAD_THREAD); + proxy->bind(new Ref<Thread>(thread), JIN_THREAD_THREAD); return 1; } @@ -232,8 +231,8 @@ namespace lua } static const luaL_Reg f[] = { - { "Thread", l_newThread}, - { "getThread", l_getThread}, + { "Thread", l_newThread }, + { "getThread", l_getThread }, { 0, 0 } }; diff --git a/src/lua/thread/luaopen_thread.cpp b/src/lua/thread/luaopen_thread.cpp index eaa263d..5d44c30 100644 --- a/src/lua/thread/luaopen_thread.cpp +++ b/src/lua/thread/luaopen_thread.cpp @@ -219,8 +219,7 @@ namespace lua const char* code = luax_checkstring(L, 2); Proxy* proxy = (Proxy*)luax_newinstance(L, JIN_THREAD_THREAD, sizeof(Proxy)); Thread* thread = new Thread(name, code, threadRunner); - Ref<Thread>* ref = new Ref<Thread>(thread); - proxy->bind(ref, JIN_THREAD_THREAD); + proxy->bind(new Ref<Thread>(thread), JIN_THREAD_THREAD); return 1; } @@ -232,8 +231,8 @@ namespace lua } static const luaL_Reg f[] = { - { "Thread", l_newThread}, - { "getThread", l_getThread}, + { "Thread", l_newThread }, + { "getThread", l_getThread }, { 0, 0 } }; diff --git a/src/main.cpp b/src/main.cpp index bd1c1af..ce70e65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,5 @@ #ifdef _WIN32 -// SDL main entry #include <SDL2/SDL_Main.h> -// directory #include <direct.h> #endif @@ -12,27 +10,21 @@ #include <Windows.h> +using namespace jin::lua; + int main(int argc, char* argv[]) { - // global lua state, all lua values are here lua_State* L = luax_newstate(); - luax_openlibs(L); - /** - * open jin module, jin module is on the top - * of stack - */ - jin::lua::luaopen_jin(L); + luax_openlibs(L); + luaopen_jin(L); // add args to global field luax_newtable(L); for (int i = 0; i < argc; ++i) luax_setraw_string(L, -2, i + 1, argv[i]); luax_setfield(L, -2, "_argv"); - - /** - * jin._dir is the folder of jin binary executable - */ + const int BUFFER_SIZE = 512; char buffer[BUFFER_SIZE]; #ifdef _WIN32 @@ -43,7 +35,7 @@ int main(int argc, char* argv[]) #undef BUFFER_SIZE luax_setfield_string(L, "_dir", buffer); // boot - jin::lua::boot(L); + boot(L); luax_close(L); return 0; |