diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/3rdparty/luax/luax.h | 19 | ||||
-rw-r--r-- | src/libjin/modules.h | 4 | ||||
-rw-r--r-- | src/lua/luaopen_jin.cpp | 40 | ||||
-rw-r--r-- | src/lua/luaopen_types.h | 4 | ||||
-rw-r--r-- | src/lua/net/lua_net_Buffer.h | 6 | ||||
-rw-r--r-- | src/lua/net/luaopen_Buffer.cpp | 16 | ||||
-rw-r--r-- | src/lua/net/luaopen_net.cpp | 6 | ||||
-rw-r--r-- | src/lua/thread/luaopen_Thread.cpp | 6 | ||||
-rw-r--r-- | src/lua/thread/luaopen_thread.cpp | 6 |
9 files changed, 63 insertions, 44 deletions
diff --git a/src/3rdparty/luax/luax.h b/src/3rdparty/luax/luax.h index 6ec4dc9..56023b3 100644 --- a/src/3rdparty/luax/luax.h +++ b/src/3rdparty/luax/luax.h @@ -276,6 +276,25 @@ inline int luax_isfloat(lua_State* L, int i) return 0; return lua_tonumber(L, i) != lua_tointeger(L, i); } + +#define luax_isnumberstrict(L, i) (lua_type(L, i) == LUA_TNUMBER) +#define luax_isstringstrict(L, i) (lua_type(L, i) == LUA_TSTRING) +#define luax_isbooleanstrict(L, i) (lua_type(L, i) == LUA_TBOOLEAN) +#define luax_istablestrict(L, i) (lua_type(L, i) == LUA_TTABLE) +#define luax_isnilstrict(L, i) (lua_type(L, i) == LUA_TNIL) +inline int luax_isintegerstrict(lua_State* L, int i) +{ + if (!luax_isnumberstrict(L, i)) + return 0; + return lua_tonumber(L, i) == lua_tointeger(L, i); +} +inline int luax_isfloatstrict(lua_State* L, int i) +{ + if (!luax_isnumberstrict(L, i)) + return 0; + return lua_tonumber(L, i) != lua_tointeger(L, i); +} + /** * To userdata. */ diff --git a/src/libjin/modules.h b/src/libjin/modules.h index 6cc9336..bbfb085 100644 --- a/src/libjin/modules.h +++ b/src/libjin/modules.h @@ -22,7 +22,7 @@ #define JIN_MODULES_NET 1 #define JIN_NET_TEKCOS 1 -#define JIN_MODULES_PHYSICS 1 +#define JIN_MODULES_PHYSICS 0 #define JIN_PHYSICS_BOX2D 1 #define JIN_PHYSICS_NEWTON 1 @@ -30,7 +30,7 @@ #define JIN_MODULES_UI 1 -#define JIN_MODULES_TOOLS 1 +#define JIN_MODULES_TOOLS 0 #define JIN_TOOLS_COMPONENT 1 #define JIN_TOOLS_EVENTMSGCENTER 1 #define JIN_TOOLS_XML 1 diff --git a/src/lua/luaopen_jin.cpp b/src/lua/luaopen_jin.cpp index ad5b193..4697ec2 100644 --- a/src/lua/luaopen_jin.cpp +++ b/src/lua/luaopen_jin.cpp @@ -44,7 +44,7 @@ namespace lua #endif return 1; } - + static int l_revision(lua_State* L) { luax_pushnumber(L, REVISION); @@ -52,29 +52,29 @@ namespace lua } static const luaL_Reg f[] = { - {"version", l_getversion}, - {"revision", l_revision}, - {"author", l_getAuthor}, - {"os", l_getOS}, - {0, 0} + { "version", l_getversion }, + { "revision", l_revision }, + { "author", l_getAuthor }, + { "os", l_getOS }, + { 0, 0 } }; // submodules static const luaL_Reg mods[] = { - {"core", luaopen_core}, - {"event", luaopen_event}, - {"graphics", luaopen_graphics}, - {"time", luaopen_time}, - {"mouse", luaopen_mouse}, - {"keyboard", luaopen_keyboard}, - {"filesystem", luaopen_filesystem}, - {"net", luaopen_net}, - {"audio", luaopen_audio}, - {"joypad", luaopen_joypad}, - {"math", luaopen_math}, - {"thread", luaopen_thread}, - {"bit", luaopen_bit}, - {0, 0} + { "core", luaopen_core }, + { "event", luaopen_event }, + { "graphics", luaopen_graphics }, + { "time", luaopen_time }, + { "mouse", luaopen_mouse }, + { "keyboard", luaopen_keyboard }, + { "filesystem", luaopen_filesystem }, + { "net", luaopen_net }, + { "audio", luaopen_audio }, + { "joypad", luaopen_joypad }, + { "math", luaopen_math }, + { "thread", luaopen_thread }, + { "bit", luaopen_bit }, + { 0, 0 } }; int luaopen_jin(lua_State* L) diff --git a/src/lua/luaopen_types.h b/src/lua/luaopen_types.h index ba720ee..eef4a3e 100644 --- a/src/lua/luaopen_types.h +++ b/src/lua/luaopen_types.h @@ -35,7 +35,7 @@ namespace lua const char* type; // type name and metatable name }; -} -} +} // lua +} // jin #endif
\ No newline at end of file diff --git a/src/lua/net/lua_net_Buffer.h b/src/lua/net/lua_net_Buffer.h index 51c7598..7fba37f 100644 --- a/src/lua/net/lua_net_Buffer.h +++ b/src/lua/net/lua_net_Buffer.h @@ -65,19 +65,19 @@ namespace net int grabInteger(int* length, int offset = 0) { *length = sizeof(int); - return *((int*)buffer); + return *((int*)(buffer + offset)); } float grabFloat(int* length, int offset = 0) { *length = sizeof(float); - return *((float*)buffer); + return *((float*)(buffer + offset)); } bool grabBoolean(int* length, int offset = 0) { *length = sizeof(bool); - return *((bool*)buffer); + return *((bool*)(buffer + offset)); } char* buffer; diff --git a/src/lua/net/luaopen_Buffer.cpp b/src/lua/net/luaopen_Buffer.cpp index 3a8353b..9278544 100644 --- a/src/lua/net/luaopen_Buffer.cpp +++ b/src/lua/net/luaopen_Buffer.cpp @@ -23,15 +23,15 @@ namespace net { Buffer* buffer = checkNetBuffer(L); const int vp = 2; - if (luax_isinteger(L, vp)) + if (luax_isintegerstrict(L, vp)) { int n = luax_checkinteger(L, vp); int size = sizeof(n); buffer->append(&n, size); luax_pushinteger(L, size); return 1; - } - else if (luax_isfloat(L, vp)) + } + else if (luax_isfloatstrict(L, vp)) { float n = luax_checknumber(L, vp); int size = sizeof(n); @@ -39,7 +39,7 @@ namespace net luax_pushinteger(L, size); return 1; } - else if (luax_isboolean(L, vp)) + else if (luax_isbooleanstrict(L, vp)) { bool n = luax_checkbool(L, vp); int size = sizeof(n); @@ -47,7 +47,7 @@ namespace net luax_pushinteger(L, size); return 1; } - else if (luax_isstring(L, vp)) + else if (luax_isstringstrict(L, vp)) { const char* str = luax_checkstring(L, vp); int size = strlen(str) + 1; @@ -83,7 +83,7 @@ namespace net int integer = buffer->grabInteger(&len, offset); luax_pushinteger(L, integer); luax_pushinteger(L, len); - return 1; + return 2; } static int l_grabFloat(lua_State* L) @@ -94,7 +94,7 @@ namespace net float floatv = buffer->grabFloat(&len, offset); luax_pushnumber(L, floatv); luax_pushinteger(L, len); - return 1; + return 2; } static int l_grabBoolean(lua_State* L) @@ -105,7 +105,7 @@ namespace net bool boolean = buffer->grabBoolean(&len, offset); luax_pushboolean(L, boolean); luax_pushinteger(L, len); - return 1; + return 2; } static const luaL_Reg netbuffer_function[] = { diff --git a/src/lua/net/luaopen_net.cpp b/src/lua/net/luaopen_net.cpp index 4bbb7e8..e2b9a9a 100644 --- a/src/lua/net/luaopen_net.cpp +++ b/src/lua/net/luaopen_net.cpp @@ -47,9 +47,9 @@ namespace lua // type, address, port else if (luax_gettop(L) == 3) { - if (luax_isstring(L, 2)) + if (luax_isstringstrict(L, 2)) info.address = tk_strtohl(luax_checkstring(L, 2)); - else if(luax_isinteger(L, 2)) + else if(luax_isintegerstrict(L, 2)) info.address = luax_checkinteger(L, 2); info.port = luax_checkinteger(L, 3); } @@ -64,7 +64,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(); + net::Buffer* buffer = new net::Buffer(size); proxy->bind(buffer, JIN_NETWORK_BUFFER); return 1; } diff --git a/src/lua/thread/luaopen_Thread.cpp b/src/lua/thread/luaopen_Thread.cpp index b16a114..393a29d 100644 --- a/src/lua/thread/luaopen_Thread.cpp +++ b/src/lua/thread/luaopen_Thread.cpp @@ -75,17 +75,17 @@ namespace jin Thread* t = checkThread(L); int slot = luax_checkinteger(L, 2); const int vp = 3; - if (luax_isnumber(L, vp)) + if (luax_isnumberstrict(L, vp)) { float real = luax_checknumber(L, vp); t->send(slot, real); } - else if (luax_isboolean(L, vp)) + else if (luax_isbooleanstrict(L, vp)) { bool bol = luax_checkbool(L, vp); t->send(slot, bol); } - else if (luax_isstring(L, vp)) + else if (luax_isstringstrict(L, vp)) { const char* str = luax_checkstring(L, vp); t->send(slot, str); diff --git a/src/lua/thread/luaopen_thread.cpp b/src/lua/thread/luaopen_thread.cpp index b16a114..393a29d 100644 --- a/src/lua/thread/luaopen_thread.cpp +++ b/src/lua/thread/luaopen_thread.cpp @@ -75,17 +75,17 @@ namespace jin Thread* t = checkThread(L); int slot = luax_checkinteger(L, 2); const int vp = 3; - if (luax_isnumber(L, vp)) + if (luax_isnumberstrict(L, vp)) { float real = luax_checknumber(L, vp); t->send(slot, real); } - else if (luax_isboolean(L, vp)) + else if (luax_isbooleanstrict(L, vp)) { bool bol = luax_checkbool(L, vp); t->send(slot, bol); } - else if (luax_isstring(L, vp)) + else if (luax_isstringstrict(L, vp)) { const char* str = luax_checkstring(L, vp); t->send(slot, str); |