diff options
-rw-r--r-- | lapi.c | 28 | ||||
-rw-r--r-- | ltests.c | 16 | ||||
-rw-r--r-- | lua.h | 31 |
3 files changed, 51 insertions, 24 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.78 2009/06/01 19:09:26 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.79 2009/06/15 19:51:31 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -275,32 +275,34 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { | |||
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | LUA_API int lua_equal (lua_State *L, int index1, int index2) { | 278 | LUA_API void lua_arith (lua_State *L, int op) { |
279 | StkId o1, o2; | 279 | lua_lock(L); |
280 | int i; | 280 | api_checknelems(L, 2); |
281 | lua_lock(L); /* may call tag method */ | 281 | luaV_arith(L, L->top - 2, L->top - 2, L->top - 1, op - LUA_OPADD + TM_ADD); |
282 | o1 = index2adr(L, index1); | 282 | L->top--; |
283 | o2 = index2adr(L, index2); | ||
284 | i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 : equalobj(L, o1, o2); | ||
285 | lua_unlock(L); | 283 | lua_unlock(L); |
286 | return i; | ||
287 | } | 284 | } |
288 | 285 | ||
289 | 286 | ||
290 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2) { | 287 | LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) { |
291 | StkId o1, o2; | 288 | StkId o1, o2; |
292 | int i; | 289 | int i; |
293 | lua_lock(L); /* may call tag method */ | 290 | lua_lock(L); /* may call tag method */ |
294 | o1 = index2adr(L, index1); | 291 | o1 = index2adr(L, index1); |
295 | o2 = index2adr(L, index2); | 292 | o2 = index2adr(L, index2); |
296 | i = (o1 == luaO_nilobject || o2 == luaO_nilobject) ? 0 | 293 | if (o1 == luaO_nilobject || o2 == luaO_nilobject) |
297 | : luaV_lessthan(L, o1, o2); | 294 | i = 0; |
295 | else switch (op) { | ||
296 | case LUA_OPEQ: i = equalobj(L, o1, o2); break; | ||
297 | case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break; | ||
298 | case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break; | ||
299 | default: api_check(L, 0); i = 0; | ||
300 | } | ||
298 | lua_unlock(L); | 301 | lua_unlock(L); |
299 | return i; | 302 | return i; |
300 | } | 303 | } |
301 | 304 | ||
302 | 305 | ||
303 | |||
304 | LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { | 306 | LUA_API lua_Number lua_tonumber (lua_State *L, int idx) { |
305 | TValue n; | 307 | TValue n; |
306 | const TValue *o = index2adr(L, idx); | 308 | const TValue *o = index2adr(L, idx); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.64 2009/06/10 16:57:53 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.65 2009/06/15 19:51:31 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -971,13 +971,17 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
971 | else if EQ("concat") { | 971 | else if EQ("concat") { |
972 | lua_concat(L1, getnum); | 972 | lua_concat(L1, getnum); |
973 | } | 973 | } |
974 | else if EQ("lessthan") { | 974 | else if EQ("arith") { |
975 | int a = getindex; | 975 | static char ops[] = "+-*/%^_"; |
976 | lua_pushboolean(L1, lua_lessthan(L1, a, getindex)); | 976 | int op; |
977 | skip(&pc); | ||
978 | op = strchr(ops, *pc++) - ops; | ||
979 | lua_arith(L, op); | ||
977 | } | 980 | } |
978 | else if EQ("equal") { | 981 | else if EQ("compare") { |
979 | int a = getindex; | 982 | int a = getindex; |
980 | lua_pushboolean(L1, lua_equal(L1, a, getindex)); | 983 | int b = getindex; |
984 | lua_pushboolean(L1, lua_compare(L1, a, b, getnum)); | ||
981 | } | 985 | } |
982 | else if EQ("call") { | 986 | else if EQ("call") { |
983 | int narg = getnum; | 987 | int narg = getnum; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.237 2009/05/21 20:06:11 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.238 2009/06/15 19:51:31 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
@@ -147,10 +147,6 @@ LUA_API int (lua_isuserdata) (lua_State *L, int idx); | |||
147 | LUA_API int (lua_type) (lua_State *L, int idx); | 147 | LUA_API int (lua_type) (lua_State *L, int idx); |
148 | LUA_API const char *(lua_typename) (lua_State *L, int tp); | 148 | LUA_API const char *(lua_typename) (lua_State *L, int tp); |
149 | 149 | ||
150 | LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); | ||
151 | LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); | ||
152 | LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); | ||
153 | |||
154 | LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); | 150 | LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); |
155 | LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); | 151 | LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); |
156 | LUA_API int (lua_toboolean) (lua_State *L, int idx); | 152 | LUA_API int (lua_toboolean) (lua_State *L, int idx); |
@@ -163,6 +159,28 @@ LUA_API const void *(lua_topointer) (lua_State *L, int idx); | |||
163 | 159 | ||
164 | 160 | ||
165 | /* | 161 | /* |
162 | ** Comparison and arithmetic functions | ||
163 | */ | ||
164 | |||
165 | #define LUA_OPADD 0 /* ORDER TM */ | ||
166 | #define LUA_OPSUB 1 | ||
167 | #define LUA_OPMUL 2 | ||
168 | #define LUA_OPDIV 3 | ||
169 | #define LUA_OPMOD 4 | ||
170 | #define LUA_OPPOW 5 | ||
171 | #define LUA_OPUNM 6 | ||
172 | |||
173 | LUA_API void (lua_arith) (lua_State *L, int op); | ||
174 | |||
175 | #define LUA_OPEQ 0 | ||
176 | #define LUA_OPLT 1 | ||
177 | #define LUA_OPLE 2 | ||
178 | |||
179 | LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); | ||
180 | LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op); | ||
181 | |||
182 | |||
183 | /* | ||
166 | ** push functions (C -> stack) | 184 | ** push functions (C -> stack) |
167 | */ | 185 | */ |
168 | LUA_API void (lua_pushnil) (lua_State *L); | 186 | LUA_API void (lua_pushnil) (lua_State *L); |
@@ -310,6 +328,9 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); | |||
310 | #define lua_Chunkreader lua_Reader | 328 | #define lua_Chunkreader lua_Reader |
311 | #define lua_Chunkwriter lua_Writer | 329 | #define lua_Chunkwriter lua_Writer |
312 | 330 | ||
331 | #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) | ||
332 | #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) | ||
333 | |||
313 | #endif | 334 | #endif |
314 | 335 | ||
315 | 336 | ||