From 489cd678823e0981ff2e4d2544b84094ed23c587 Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Tue, 20 Jan 2015 01:02:20 +0100 Subject: add lua_arith and lua_compare for Lua 5.1 --- tests/test.lua | 9 +++++++++ tests/testmod.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) (limited to 'tests') diff --git a/tests/test.lua b/tests/test.lua index b59fd94..2b53b92 100755 --- a/tests/test.lua +++ b/tests/test.lua @@ -313,6 +313,15 @@ print(mod.getupvalues()) ___'' print(mod.absindex("hi", true)) +___'' +print(mod.arith(2, 1)) +print(mod.arith(3, 5)) + +___'' +print(mod.compare(1, 1)) +print(mod.compare(2, 1)) +print(mod.compare(1, 2)) + ___'' print(mod.tolstring("string")) local t = setmetatable({}, { 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) { return i; } +static int test_arith (lua_State *L) { + lua_settop(L, 2); + lua_pushvalue(L, 1); + lua_pushvalue(L, 2); + lua_arith(L, LUA_OPADD); + lua_pushvalue(L, 1); + lua_pushvalue(L, 2); + lua_arith(L, LUA_OPSUB); + lua_pushvalue(L, 1); + lua_pushvalue(L, 2); + lua_arith(L, LUA_OPMUL); + lua_pushvalue(L, 1); + lua_pushvalue(L, 2); + lua_arith(L, LUA_OPDIV); + lua_pushvalue(L, 1); + lua_pushvalue(L, 2); + lua_arith(L, LUA_OPMOD); + lua_pushvalue(L, 1); + lua_pushvalue(L, 2); + lua_arith(L, LUA_OPPOW); + lua_pushvalue(L, 1); + lua_arith(L, LUA_OPUNM); + return lua_gettop(L)-2; +} + +static int test_compare (lua_State *L) { + luaL_checknumber(L, 1); + luaL_checknumber(L, 2); + lua_settop(L, 2); + lua_pushboolean(L, lua_compare(L, 1, 2, LUA_OPEQ)); + lua_pushboolean(L, lua_compare(L, 1, 2, LUA_OPLT)); + lua_pushboolean(L, lua_compare(L, 1, 2, LUA_OPLE)); + return 3; +} + static int test_globals (lua_State *L) { lua_pushglobaltable(L); return 1; @@ -215,6 +250,8 @@ static const luaL_Reg funcs[] = { { "requiref", test_requiref }, { "getseti", test_getseti }, { "newproxy", test_newproxy }, + { "arith", test_arith }, + { "compare", test_compare }, { "tonumber", test_tonumber }, { "tointeger", test_tointeger }, { "len", test_len }, -- cgit v1.2.3-55-g6feb