diff options
| author | Philipp Janda <siffiejoe@gmx.net> | 2015-01-20 01:02:20 +0100 |
|---|---|---|
| committer | Philipp Janda <siffiejoe@gmx.net> | 2015-01-20 01:02:20 +0100 |
| commit | 489cd678823e0981ff2e4d2544b84094ed23c587 (patch) | |
| tree | 2855dbabb9205957434129aa1119cb526d2ae01b /tests | |
| parent | f7f85b0826f7006b8dcc040111cd0ef8d42c2352 (diff) | |
| download | lua-compat-5.3-489cd678823e0981ff2e4d2544b84094ed23c587.tar.gz lua-compat-5.3-489cd678823e0981ff2e4d2544b84094ed23c587.tar.bz2 lua-compat-5.3-489cd678823e0981ff2e4d2544b84094ed23c587.zip | |
add lua_arith and lua_compare for Lua 5.1
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/test.lua | 9 | ||||
| -rw-r--r-- | tests/testmod.c | 37 |
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/test.lua b/tests/test.lua index b59fd94..2b53b92 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
| @@ -314,6 +314,15 @@ ___'' | |||
| 314 | print(mod.absindex("hi", true)) | 314 | print(mod.absindex("hi", true)) |
| 315 | 315 | ||
| 316 | ___'' | 316 | ___'' |
| 317 | print(mod.arith(2, 1)) | ||
| 318 | print(mod.arith(3, 5)) | ||
| 319 | |||
| 320 | ___'' | ||
| 321 | print(mod.compare(1, 1)) | ||
| 322 | print(mod.compare(2, 1)) | ||
| 323 | print(mod.compare(1, 2)) | ||
| 324 | |||
| 325 | ___'' | ||
| 317 | print(mod.tolstring("string")) | 326 | print(mod.tolstring("string")) |
| 318 | local t = setmetatable({}, { | 327 | local t = setmetatable({}, { |
| 319 | __tostring = function(v) return "mytable" end | 328 | __tostring = function(v) return "mytable" end |
diff --git a/tests/testmod.c b/tests/testmod.c index a9c8e8d..2c6242b 100644 --- a/tests/testmod.c +++ b/tests/testmod.c | |||
| @@ -96,6 +96,41 @@ static int test_absindex (lua_State *L) { | |||
| 96 | return i; | 96 | return i; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | static int test_arith (lua_State *L) { | ||
| 100 | lua_settop(L, 2); | ||
| 101 | lua_pushvalue(L, 1); | ||
| 102 | lua_pushvalue(L, 2); | ||
| 103 | lua_arith(L, LUA_OPADD); | ||
| 104 | lua_pushvalue(L, 1); | ||
| 105 | lua_pushvalue(L, 2); | ||
| 106 | lua_arith(L, LUA_OPSUB); | ||
| 107 | lua_pushvalue(L, 1); | ||
| 108 | lua_pushvalue(L, 2); | ||
| 109 | lua_arith(L, LUA_OPMUL); | ||
| 110 | lua_pushvalue(L, 1); | ||
| 111 | lua_pushvalue(L, 2); | ||
| 112 | lua_arith(L, LUA_OPDIV); | ||
| 113 | lua_pushvalue(L, 1); | ||
| 114 | lua_pushvalue(L, 2); | ||
| 115 | lua_arith(L, LUA_OPMOD); | ||
| 116 | lua_pushvalue(L, 1); | ||
| 117 | lua_pushvalue(L, 2); | ||
| 118 | lua_arith(L, LUA_OPPOW); | ||
| 119 | lua_pushvalue(L, 1); | ||
| 120 | lua_arith(L, LUA_OPUNM); | ||
| 121 | return lua_gettop(L)-2; | ||
| 122 | } | ||
| 123 | |||
| 124 | static int test_compare (lua_State *L) { | ||
| 125 | luaL_checknumber(L, 1); | ||
| 126 | luaL_checknumber(L, 2); | ||
| 127 | lua_settop(L, 2); | ||
| 128 | lua_pushboolean(L, lua_compare(L, 1, 2, LUA_OPEQ)); | ||
| 129 | lua_pushboolean(L, lua_compare(L, 1, 2, LUA_OPLT)); | ||
| 130 | lua_pushboolean(L, lua_compare(L, 1, 2, LUA_OPLE)); | ||
| 131 | return 3; | ||
| 132 | } | ||
| 133 | |||
| 99 | static int test_globals (lua_State *L) { | 134 | static int test_globals (lua_State *L) { |
| 100 | lua_pushglobaltable(L); | 135 | lua_pushglobaltable(L); |
| 101 | return 1; | 136 | return 1; |
| @@ -215,6 +250,8 @@ static const luaL_Reg funcs[] = { | |||
| 215 | { "requiref", test_requiref }, | 250 | { "requiref", test_requiref }, |
| 216 | { "getseti", test_getseti }, | 251 | { "getseti", test_getseti }, |
| 217 | { "newproxy", test_newproxy }, | 252 | { "newproxy", test_newproxy }, |
| 253 | { "arith", test_arith }, | ||
| 254 | { "compare", test_compare }, | ||
| 218 | { "tonumber", test_tonumber }, | 255 | { "tonumber", test_tonumber }, |
| 219 | { "tointeger", test_tointeger }, | 256 | { "tointeger", test_tointeger }, |
| 220 | { "len", test_len }, | 257 | { "len", test_len }, |
