Skip to content

Commit

Permalink
修复64 位除0问题
Browse files Browse the repository at this point in the history
  • Loading branch information
topameng committed Aug 17, 2017
1 parent 52dbe46 commit ecfc361
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 19 deletions.
Binary file modified Plugins/Android/libs/armeabi-v7a/libtolua.so
Binary file not shown.
Binary file modified Plugins/Android/libs/x86/libtolua.so
Binary file not shown.
Binary file modified Plugins/iOS/libtolua.a
Binary file not shown.
2 changes: 1 addition & 1 deletion Plugins/tolua.bundle/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@
<key>DTXcodeBuild</key>
<string>8E2002</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2013 topameng. All rights reserved.</string>
<string>Copyright © 2014 topameng. All rights reserved.</string>
</dict>
</plist>
Binary file modified Plugins/tolua.bundle/Contents/MacOS/tolua
Binary file not shown.
Binary file modified Plugins/x86/tolua.dll
Binary file not shown.
Binary file modified Plugins/x86_64/tolua.dll
Binary file not shown.
14 changes: 10 additions & 4 deletions int64.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ LUALIB_API bool tolua_isint64(lua_State* L, int pos)

LUALIB_API void tolua_pushint64(lua_State* L, int64_t n)
{
if (toluaflags & FLAG_INT64)
/*if (toluaflags & FLAG_INT64)
{
lua_pushinteger(L, (lua_Integer)n);
}
else
{
{*/
int64_t* p = (int64_t*)lua_newuserdata(L, sizeof(int64_t));
*p = n;
lua_getref(L, LUA_RIDX_INT64);
lua_setmetatable(L, -2);
}
//}
}

//转换一个字符串为 int64
Expand Down Expand Up @@ -211,6 +211,12 @@ static int _int64div(lua_State* L)
{
int64_t lhs = tolua_checkint64(L, 1);
int64_t rhs = tolua_checkint64(L, 2);

if (rhs == 0)
{
return luaL_error(L, "div by zero");
}

tolua_pushint64(L, lhs / rhs);
return 1;
}
Expand Down Expand Up @@ -272,7 +278,7 @@ static int _int64eq(lua_State* L)
static int _int64equals(lua_State* L)
{
int64_t lhs = tolua_checkint64(L, 1);
int64_t rhs = tolua_checkint64(L, 2);
int64_t rhs = tolua_toint64(L, 2);
lua_pushboolean(L, lhs == rhs);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion tolua.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
#define TOLUA_NOPEER LUA_REGISTRYINDEX
#define FLAG_INDEX_ERROR 1
#define FLAG_INT64 2
#define FLAG_UINT64 4

#define MAX_ITEM 512

#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : lua_gettop(L) + (i) + 1)

void tolua_openint64(lua_State* L);
int tolua_newint64(lua_State* L);
void tolua_pushint64(lua_State* L, int64_t n);

void tolua_openuint64(lua_State* L);
int tolua_newuint64(lua_State* L);
Expand Down
33 changes: 20 additions & 13 deletions uint64.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,10 @@ LUALIB_API bool tolua_isuint64(lua_State *L, int pos)

LUALIB_API void tolua_pushuint64(lua_State *L, uint64_t n)
{
if (toluaflags & FLAG_UINT64)
{
lua_pushinteger(L, (lua_Integer)n);
}
else
{
uint64_t* p = (uint64_t*)lua_newuserdata(L, sizeof(uint64_t));
*p = n;
lua_getref(L, LUA_RIDX_UINT64);
lua_setmetatable(L, -2);
}
uint64_t* p = (uint64_t*)lua_newuserdata(L, sizeof(uint64_t));
*p = n;
lua_getref(L, LUA_RIDX_UINT64);
lua_setmetatable(L, -2);
}

//转换一个字符串为 uint64
Expand Down Expand Up @@ -194,7 +187,15 @@ static int _uint64sub(lua_State *L)
{
uint64_t lhs = tolua_checkuint64(L, 1);
uint64_t rhs = tolua_checkuint64(L, 2);
tolua_pushuint64(L, lhs - rhs);

if (lhs > rhs)
{
tolua_pushuint64(L, lhs - rhs);
}
else
{
tolua_pushint64(L, lhs - rhs);
}
return 1;
}

Expand All @@ -210,6 +211,12 @@ static int _uint64div(lua_State *L)
{
uint64_t lhs = tolua_checkuint64(L, 1);
uint64_t rhs = tolua_checkuint64(L, 2);

if (rhs == 0)
{
return luaL_error(L, "div by zero");
}

tolua_pushuint64(L, lhs / rhs);
return 1;
}
Expand Down Expand Up @@ -271,7 +278,7 @@ static int _uint64eq(lua_State *L)
static int _uint64equals(lua_State *L)
{
uint64_t lhs = tolua_checkuint64(L, 1);
uint64_t rhs = tolua_checkuint64(L, 2);
uint64_t rhs = tolua_touint64(L, 2);
lua_pushboolean(L, lhs == rhs);
return 1;
}
Expand Down
Binary file modified window/x86/libluajit.a
Binary file not shown.
Binary file modified window/x86_64/libluajit.a
Binary file not shown.

0 comments on commit ecfc361

Please sign in to comment.