aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPhilipp Janda <siffiejoe@gmx.net>2015-01-20 01:02:20 +0100
committerPhilipp Janda <siffiejoe@gmx.net>2015-01-20 01:02:20 +0100
commit489cd678823e0981ff2e4d2544b84094ed23c587 (patch)
tree2855dbabb9205957434129aa1119cb526d2ae01b /tests
parentf7f85b0826f7006b8dcc040111cd0ef8d42c2352 (diff)
downloadlua-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-xtests/test.lua9
-rw-r--r--tests/testmod.c37
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 @@ ___''
314print(mod.absindex("hi", true)) 314print(mod.absindex("hi", true))
315 315
316___'' 316___''
317print(mod.arith(2, 1))
318print(mod.arith(3, 5))
319
320___''
321print(mod.compare(1, 1))
322print(mod.compare(2, 1))
323print(mod.compare(1, 2))
324
325___''
317print(mod.tolstring("string")) 326print(mod.tolstring("string"))
318local t = setmetatable({}, { 327local 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
99static 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
124static 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
99static int test_globals (lua_State *L) { 134static 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 },