diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-09-14 11:09:31 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-09-14 11:09:31 -0300 |
commit | 620d22f2a09ccfe5b7a09ebc11a7b5dca28ac9e4 (patch) | |
tree | e0a789478ca78f601d4fc05b62feddb978914a65 | |
parent | f45cba42b5c32758337f62c56e98fdb85a9f4af2 (diff) | |
download | lua-620d22f2a09ccfe5b7a09ebc11a7b5dca28ac9e4.tar.gz lua-620d22f2a09ccfe5b7a09ebc11a7b5dca28ac9e4.tar.bz2 lua-620d22f2a09ccfe5b7a09ebc11a7b5dca28ac9e4.zip |
new API function lua_rawget
-rw-r--r-- | lapi.c | 11 | ||||
-rw-r--r-- | lbaselib.c | 17 | ||||
-rw-r--r-- | liolib.c | 4 | ||||
-rw-r--r-- | lstrlib.c | 7 | ||||
-rw-r--r-- | ltests.c | 19 | ||||
-rw-r--r-- | lua.h | 3 |
6 files changed, 40 insertions, 21 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.96 2000/09/11 20:29:27 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.97 2000/09/12 13:47:46 roberto Exp $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -366,6 +366,15 @@ int lua_ref (lua_State *L, int lock) { | |||
366 | } | 366 | } |
367 | 367 | ||
368 | 368 | ||
369 | /* | ||
370 | ** "do" functions (run Lua code) | ||
371 | ** (most of them are in ldo.c) | ||
372 | */ | ||
373 | |||
374 | void lua_rawcall (lua_State *L, int nargs, int nresults) { | ||
375 | luaD_call(L, L->top-(nargs+1), nresults); | ||
376 | } | ||
377 | |||
369 | 378 | ||
370 | /* | 379 | /* |
371 | ** miscellaneous functions | 380 | ** miscellaneous functions |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.3 2000/09/12 18:41:43 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.4 2000/09/13 19:52:39 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -51,7 +51,7 @@ static int luaB__ERRORMESSAGE (lua_State *L) { | |||
51 | } | 51 | } |
52 | lua_pushstring(L, "\n"); | 52 | lua_pushstring(L, "\n"); |
53 | lua_concat(L, 3); | 53 | lua_concat(L, 3); |
54 | lua_call(L, 1, 0); | 54 | lua_rawcall(L, 1, 0); |
55 | } | 55 | } |
56 | return 0; | 56 | return 0; |
57 | } | 57 | } |
@@ -71,8 +71,7 @@ static int luaB_print (lua_State *L) { | |||
71 | const char *s; | 71 | const char *s; |
72 | lua_pushvalue(L, -1); /* function to be called */ | 72 | lua_pushvalue(L, -1); /* function to be called */ |
73 | lua_pushvalue(L, i); /* value to print */ | 73 | lua_pushvalue(L, i); /* value to print */ |
74 | if (lua_call(L, 1, 1) != 0) | 74 | lua_rawcall(L, 1, 1); |
75 | lua_error(L, NULL); | ||
76 | s = lua_tostring(L, -1); /* get result */ | 75 | s = lua_tostring(L, -1); /* get result */ |
77 | if (s == NULL) | 76 | if (s == NULL) |
78 | lua_error(L, "`tostring' must return a string to `print'"); | 77 | lua_error(L, "`tostring' must return a string to `print'"); |
@@ -335,8 +334,7 @@ static int luaB_foreachi (lua_State *L) { | |||
335 | lua_pushvalue(L, 2); /* function */ | 334 | lua_pushvalue(L, 2); /* function */ |
336 | lua_pushnumber(L, i); /* 1st argument */ | 335 | lua_pushnumber(L, i); /* 1st argument */ |
337 | lua_rawgeti(L, 1, i); /* 2nd argument */ | 336 | lua_rawgeti(L, 1, i); /* 2nd argument */ |
338 | if (lua_call(L, 2, 1) != 0) | 337 | lua_rawcall(L, 2, 1); |
339 | lua_error(L, NULL); | ||
340 | if (!lua_isnil(L, -1)) | 338 | if (!lua_isnil(L, -1)) |
341 | return 1; | 339 | return 1; |
342 | lua_pop(L, 1); /* remove nil result */ | 340 | lua_pop(L, 1); /* remove nil result */ |
@@ -355,7 +353,7 @@ static int luaB_foreach (lua_State *L) { | |||
355 | lua_pushvalue(L, 2); /* function */ | 353 | lua_pushvalue(L, 2); /* function */ |
356 | lua_pushvalue(L, -3); /* key */ | 354 | lua_pushvalue(L, -3); /* key */ |
357 | lua_pushvalue(L, -3); /* value */ | 355 | lua_pushvalue(L, -3); /* value */ |
358 | if (lua_call(L, 2, 1) != 0) lua_error(L, NULL); | 356 | lua_rawcall(L, 2, 1); |
359 | if (!lua_isnil(L, -1)) | 357 | if (!lua_isnil(L, -1)) |
360 | return 1; | 358 | return 1; |
361 | lua_pop(L, 2); /* remove value and result */ | 359 | lua_pop(L, 2); /* remove value and result */ |
@@ -450,7 +448,7 @@ static int sort_comp (lua_State *L, int n, int r) { | |||
450 | lua_pushvalue(L, -2); /* pivot */ | 448 | lua_pushvalue(L, -2); /* pivot */ |
451 | lua_rawgeti(L, 1, n); /* a[n] */ | 449 | lua_rawgeti(L, 1, n); /* a[n] */ |
452 | } | 450 | } |
453 | if (lua_call(L, 2, 1) != 0) lua_error(L, NULL); | 451 | lua_rawcall(L, 2, 1); |
454 | res = !lua_isnil(L, -1); | 452 | res = !lua_isnil(L, -1); |
455 | } | 453 | } |
456 | else { /* a < b? */ | 454 | else { /* a < b? */ |
@@ -553,8 +551,7 @@ static int deprecated_func (lua_State *L) { | |||
553 | lua_insert(L, 1); /* upvalue is the function to be called */ | 551 | lua_insert(L, 1); /* upvalue is the function to be called */ |
554 | lua_getglobals(L); | 552 | lua_getglobals(L); |
555 | lua_insert(L, 2); /* table of globals is 1o argument */ | 553 | lua_insert(L, 2); /* table of globals is 1o argument */ |
556 | if (lua_call(L, lua_gettop(L)-1, LUA_MULTRET) != 0) | 554 | lua_rawcall(L, lua_gettop(L)-1, LUA_MULTRET); |
557 | lua_error(L, NULL); | ||
558 | return lua_gettop(L); /* return all results */ | 555 | return lua_gettop(L); /* return all results */ |
559 | } | 556 | } |
560 | 557 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.82 2000/09/12 18:41:55 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.83 2000/09/13 20:12:14 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -654,7 +654,7 @@ static int errorfb (lua_State *L) { | |||
654 | lua_getglobal(L, LUA_ALERT); | 654 | lua_getglobal(L, LUA_ALERT); |
655 | if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */ | 655 | if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */ |
656 | lua_pushvalue(L, -2); /* error message */ | 656 | lua_pushvalue(L, -2); /* error message */ |
657 | lua_call(L, 1, 0); | 657 | lua_rawcall(L, 1, 0); |
658 | } | 658 | } |
659 | return 0; | 659 | return 0; |
660 | } | 660 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.51 2000/09/05 19:33:32 roberto Exp $ | 2 | ** $Id: lstrlib.c,v 1.52 2000/09/11 17:38:42 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -457,13 +457,10 @@ static void add_s (lua_State *L, luaL_Buffer *b, struct Capture *cap) { | |||
457 | } | 457 | } |
458 | } | 458 | } |
459 | else { /* is a function */ | 459 | else { /* is a function */ |
460 | int status; | ||
461 | int n; | 460 | int n; |
462 | lua_pushvalue(L, 3); | 461 | lua_pushvalue(L, 3); |
463 | n = push_captures(L, cap); | 462 | n = push_captures(L, cap); |
464 | status = lua_call(L, n, 1); | 463 | lua_rawcall(L, n, 1); |
465 | if (status != 0) | ||
466 | lua_error(L, NULL); /* propagate error */ | ||
467 | if (lua_isstring(L, -1)) | 464 | if (lua_isstring(L, -1)) |
468 | luaL_addvalue(b); /* add return to accumulated result */ | 465 | luaL_addvalue(b); /* add return to accumulated result */ |
469 | else | 466 | else |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.40 2000/09/05 19:33:32 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.41 2000/09/11 19:42:57 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 | */ |
@@ -25,6 +25,7 @@ | |||
25 | #include "lstring.h" | 25 | #include "lstring.h" |
26 | #include "ltable.h" | 26 | #include "ltable.h" |
27 | #include "luadebug.h" | 27 | #include "luadebug.h" |
28 | #include "lualib.h" | ||
28 | 29 | ||
29 | 30 | ||
30 | void luaB_opentests (lua_State *L); | 31 | void luaB_opentests (lua_State *L); |
@@ -275,6 +276,19 @@ static int newstate (lua_State *L) { | |||
275 | return 1; | 276 | return 1; |
276 | } | 277 | } |
277 | 278 | ||
279 | static int loadlib (lua_State *L) { | ||
280 | lua_State *L1 = (lua_State *)lua_touserdata(L, 1); | ||
281 | switch (*luaL_check_string(L, 2)) { | ||
282 | case 'm': lua_mathlibopen(L1); break; | ||
283 | case 's': lua_strlibopen(L1); break; | ||
284 | case 'i': lua_iolibopen(L1); break; | ||
285 | case 'd': lua_dblibopen(L1); break; | ||
286 | case 'b': lua_baselibopen(L1); break; | ||
287 | default: luaL_argerror(L, 2, "invalid option"); | ||
288 | } | ||
289 | return 0; | ||
290 | } | ||
291 | |||
278 | static int closestate (lua_State *L) { | 292 | static int closestate (lua_State *L) { |
279 | luaL_checktype(L, 1, "userdata"); | 293 | luaL_checktype(L, 1, "userdata"); |
280 | lua_close((lua_State *)lua_touserdata(L, 1)); | 294 | lua_close((lua_State *)lua_touserdata(L, 1)); |
@@ -405,7 +419,7 @@ static int testC (lua_State *L) { | |||
405 | else if EQ("call") { | 419 | else if EQ("call") { |
406 | int narg = getnum; | 420 | int narg = getnum; |
407 | int nres = getnum; | 421 | int nres = getnum; |
408 | if (lua_call(L, narg, nres)) lua_error(L, NULL); | 422 | lua_rawcall(L, narg, nres); |
409 | } | 423 | } |
410 | else if EQ("type") { | 424 | else if EQ("type") { |
411 | lua_pushstring(L, lua_type(L, getnum)); | 425 | lua_pushstring(L, lua_type(L, getnum)); |
@@ -425,6 +439,7 @@ static const struct luaL_reg tests_funcs[] = { | |||
425 | {"listcode", listcode}, | 439 | {"listcode", listcode}, |
426 | {"liststrings", liststrings}, | 440 | {"liststrings", liststrings}, |
427 | {"listlocals", listlocals}, | 441 | {"listlocals", listlocals}, |
442 | {"loadlib", loadlib}, | ||
428 | {"querystr", string_query}, | 443 | {"querystr", string_query}, |
429 | {"querytab", table_query}, | 444 | {"querytab", table_query}, |
430 | {"testC", testC}, | 445 | {"testC", testC}, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.67 2000/09/11 19:42:57 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.68 2000/09/12 13:46:59 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
5 | ** e-mail: lua@tecgraf.puc-rio.br | 5 | ** e-mail: lua@tecgraf.puc-rio.br |
@@ -128,6 +128,7 @@ int lua_ref (lua_State *L, int lock); | |||
128 | ** "do" functions (run Lua code) | 128 | ** "do" functions (run Lua code) |
129 | */ | 129 | */ |
130 | int lua_call (lua_State *L, int nargs, int nresults); | 130 | int lua_call (lua_State *L, int nargs, int nresults); |
131 | void lua_rawcall (lua_State *L, int nargs, int nresults); | ||
131 | int lua_dofile (lua_State *L, const char *filename); | 132 | int lua_dofile (lua_State *L, const char *filename); |
132 | int lua_dostring (lua_State *L, const char *str); | 133 | int lua_dostring (lua_State *L, const char *str); |
133 | int lua_dobuffer (lua_State *L, const char *buff, size_t size, | 134 | int lua_dobuffer (lua_State *L, const char *buff, size_t size, |