mirror of
https://github.com/lua/lua.git
synced 2025-02-04 06:13:04 +08:00
new API function lua_rawget
This commit is contained in:
parent
f45cba42b5
commit
620d22f2a0
11
lapi.c
11
lapi.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 1.96 2000/09/11 20:29:27 roberto Exp roberto $
|
** $Id: lapi.c,v 1.97 2000/09/12 13:47:46 roberto Exp $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -366,6 +366,15 @@ int lua_ref (lua_State *L, int lock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** "do" functions (run Lua code)
|
||||||
|
** (most of them are in ldo.c)
|
||||||
|
*/
|
||||||
|
|
||||||
|
void lua_rawcall (lua_State *L, int nargs, int nresults) {
|
||||||
|
luaD_call(L, L->top-(nargs+1), nresults);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** miscellaneous functions
|
** miscellaneous functions
|
||||||
|
17
lbaselib.c
17
lbaselib.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lbaselib.c,v 1.3 2000/09/12 18:41:43 roberto Exp roberto $
|
** $Id: lbaselib.c,v 1.4 2000/09/13 19:52:39 roberto Exp roberto $
|
||||||
** Basic library
|
** Basic library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -51,7 +51,7 @@ static int luaB__ERRORMESSAGE (lua_State *L) {
|
|||||||
}
|
}
|
||||||
lua_pushstring(L, "\n");
|
lua_pushstring(L, "\n");
|
||||||
lua_concat(L, 3);
|
lua_concat(L, 3);
|
||||||
lua_call(L, 1, 0);
|
lua_rawcall(L, 1, 0);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -71,8 +71,7 @@ static int luaB_print (lua_State *L) {
|
|||||||
const char *s;
|
const char *s;
|
||||||
lua_pushvalue(L, -1); /* function to be called */
|
lua_pushvalue(L, -1); /* function to be called */
|
||||||
lua_pushvalue(L, i); /* value to print */
|
lua_pushvalue(L, i); /* value to print */
|
||||||
if (lua_call(L, 1, 1) != 0)
|
lua_rawcall(L, 1, 1);
|
||||||
lua_error(L, NULL);
|
|
||||||
s = lua_tostring(L, -1); /* get result */
|
s = lua_tostring(L, -1); /* get result */
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
lua_error(L, "`tostring' must return a string to `print'");
|
lua_error(L, "`tostring' must return a string to `print'");
|
||||||
@ -335,8 +334,7 @@ static int luaB_foreachi (lua_State *L) {
|
|||||||
lua_pushvalue(L, 2); /* function */
|
lua_pushvalue(L, 2); /* function */
|
||||||
lua_pushnumber(L, i); /* 1st argument */
|
lua_pushnumber(L, i); /* 1st argument */
|
||||||
lua_rawgeti(L, 1, i); /* 2nd argument */
|
lua_rawgeti(L, 1, i); /* 2nd argument */
|
||||||
if (lua_call(L, 2, 1) != 0)
|
lua_rawcall(L, 2, 1);
|
||||||
lua_error(L, NULL);
|
|
||||||
if (!lua_isnil(L, -1))
|
if (!lua_isnil(L, -1))
|
||||||
return 1;
|
return 1;
|
||||||
lua_pop(L, 1); /* remove nil result */
|
lua_pop(L, 1); /* remove nil result */
|
||||||
@ -355,7 +353,7 @@ static int luaB_foreach (lua_State *L) {
|
|||||||
lua_pushvalue(L, 2); /* function */
|
lua_pushvalue(L, 2); /* function */
|
||||||
lua_pushvalue(L, -3); /* key */
|
lua_pushvalue(L, -3); /* key */
|
||||||
lua_pushvalue(L, -3); /* value */
|
lua_pushvalue(L, -3); /* value */
|
||||||
if (lua_call(L, 2, 1) != 0) lua_error(L, NULL);
|
lua_rawcall(L, 2, 1);
|
||||||
if (!lua_isnil(L, -1))
|
if (!lua_isnil(L, -1))
|
||||||
return 1;
|
return 1;
|
||||||
lua_pop(L, 2); /* remove value and result */
|
lua_pop(L, 2); /* remove value and result */
|
||||||
@ -450,7 +448,7 @@ static int sort_comp (lua_State *L, int n, int r) {
|
|||||||
lua_pushvalue(L, -2); /* pivot */
|
lua_pushvalue(L, -2); /* pivot */
|
||||||
lua_rawgeti(L, 1, n); /* a[n] */
|
lua_rawgeti(L, 1, n); /* a[n] */
|
||||||
}
|
}
|
||||||
if (lua_call(L, 2, 1) != 0) lua_error(L, NULL);
|
lua_rawcall(L, 2, 1);
|
||||||
res = !lua_isnil(L, -1);
|
res = !lua_isnil(L, -1);
|
||||||
}
|
}
|
||||||
else { /* a < b? */
|
else { /* a < b? */
|
||||||
@ -553,8 +551,7 @@ static int deprecated_func (lua_State *L) {
|
|||||||
lua_insert(L, 1); /* upvalue is the function to be called */
|
lua_insert(L, 1); /* upvalue is the function to be called */
|
||||||
lua_getglobals(L);
|
lua_getglobals(L);
|
||||||
lua_insert(L, 2); /* table of globals is 1o argument */
|
lua_insert(L, 2); /* table of globals is 1o argument */
|
||||||
if (lua_call(L, lua_gettop(L)-1, LUA_MULTRET) != 0)
|
lua_rawcall(L, lua_gettop(L)-1, LUA_MULTRET);
|
||||||
lua_error(L, NULL);
|
|
||||||
return lua_gettop(L); /* return all results */
|
return lua_gettop(L); /* return all results */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
liolib.c
4
liolib.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: liolib.c,v 1.82 2000/09/12 18:41:55 roberto Exp roberto $
|
** $Id: liolib.c,v 1.83 2000/09/13 20:12:14 roberto Exp roberto $
|
||||||
** Standard I/O (and system) library
|
** Standard I/O (and system) library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -654,7 +654,7 @@ static int errorfb (lua_State *L) {
|
|||||||
lua_getglobal(L, LUA_ALERT);
|
lua_getglobal(L, LUA_ALERT);
|
||||||
if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */
|
if (lua_isfunction(L, -1)) { /* avoid loop if _ALERT is not defined */
|
||||||
lua_pushvalue(L, -2); /* error message */
|
lua_pushvalue(L, -2); /* error message */
|
||||||
lua_call(L, 1, 0);
|
lua_rawcall(L, 1, 0);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstrlib.c,v 1.51 2000/09/05 19:33:32 roberto Exp $
|
** $Id: lstrlib.c,v 1.52 2000/09/11 17:38:42 roberto Exp roberto $
|
||||||
** Standard library for string operations and pattern-matching
|
** Standard library for string operations and pattern-matching
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -457,13 +457,10 @@ static void add_s (lua_State *L, luaL_Buffer *b, struct Capture *cap) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { /* is a function */
|
else { /* is a function */
|
||||||
int status;
|
|
||||||
int n;
|
int n;
|
||||||
lua_pushvalue(L, 3);
|
lua_pushvalue(L, 3);
|
||||||
n = push_captures(L, cap);
|
n = push_captures(L, cap);
|
||||||
status = lua_call(L, n, 1);
|
lua_rawcall(L, n, 1);
|
||||||
if (status != 0)
|
|
||||||
lua_error(L, NULL); /* propagate error */
|
|
||||||
if (lua_isstring(L, -1))
|
if (lua_isstring(L, -1))
|
||||||
luaL_addvalue(b); /* add return to accumulated result */
|
luaL_addvalue(b); /* add return to accumulated result */
|
||||||
else
|
else
|
||||||
|
19
ltests.c
19
ltests.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltests.c,v 1.40 2000/09/05 19:33:32 roberto Exp roberto $
|
** $Id: ltests.c,v 1.41 2000/09/11 19:42:57 roberto Exp roberto $
|
||||||
** Internal Module for Debugging of the Lua Implementation
|
** Internal Module for Debugging of the Lua Implementation
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -25,6 +25,7 @@
|
|||||||
#include "lstring.h"
|
#include "lstring.h"
|
||||||
#include "ltable.h"
|
#include "ltable.h"
|
||||||
#include "luadebug.h"
|
#include "luadebug.h"
|
||||||
|
#include "lualib.h"
|
||||||
|
|
||||||
|
|
||||||
void luaB_opentests (lua_State *L);
|
void luaB_opentests (lua_State *L);
|
||||||
@ -275,6 +276,19 @@ static int newstate (lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int loadlib (lua_State *L) {
|
||||||
|
lua_State *L1 = (lua_State *)lua_touserdata(L, 1);
|
||||||
|
switch (*luaL_check_string(L, 2)) {
|
||||||
|
case 'm': lua_mathlibopen(L1); break;
|
||||||
|
case 's': lua_strlibopen(L1); break;
|
||||||
|
case 'i': lua_iolibopen(L1); break;
|
||||||
|
case 'd': lua_dblibopen(L1); break;
|
||||||
|
case 'b': lua_baselibopen(L1); break;
|
||||||
|
default: luaL_argerror(L, 2, "invalid option");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int closestate (lua_State *L) {
|
static int closestate (lua_State *L) {
|
||||||
luaL_checktype(L, 1, "userdata");
|
luaL_checktype(L, 1, "userdata");
|
||||||
lua_close((lua_State *)lua_touserdata(L, 1));
|
lua_close((lua_State *)lua_touserdata(L, 1));
|
||||||
@ -405,7 +419,7 @@ static int testC (lua_State *L) {
|
|||||||
else if EQ("call") {
|
else if EQ("call") {
|
||||||
int narg = getnum;
|
int narg = getnum;
|
||||||
int nres = getnum;
|
int nres = getnum;
|
||||||
if (lua_call(L, narg, nres)) lua_error(L, NULL);
|
lua_rawcall(L, narg, nres);
|
||||||
}
|
}
|
||||||
else if EQ("type") {
|
else if EQ("type") {
|
||||||
lua_pushstring(L, lua_type(L, getnum));
|
lua_pushstring(L, lua_type(L, getnum));
|
||||||
@ -425,6 +439,7 @@ static const struct luaL_reg tests_funcs[] = {
|
|||||||
{"listcode", listcode},
|
{"listcode", listcode},
|
||||||
{"liststrings", liststrings},
|
{"liststrings", liststrings},
|
||||||
{"listlocals", listlocals},
|
{"listlocals", listlocals},
|
||||||
|
{"loadlib", loadlib},
|
||||||
{"querystr", string_query},
|
{"querystr", string_query},
|
||||||
{"querytab", table_query},
|
{"querytab", table_query},
|
||||||
{"testC", testC},
|
{"testC", testC},
|
||||||
|
3
lua.h
3
lua.h
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lua.h,v 1.67 2000/09/11 19:42:57 roberto Exp roberto $
|
** $Id: lua.h,v 1.68 2000/09/12 13:46:59 roberto Exp roberto $
|
||||||
** Lua - An Extensible Extension Language
|
** Lua - An Extensible Extension Language
|
||||||
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
||||||
** e-mail: lua@tecgraf.puc-rio.br
|
** e-mail: lua@tecgraf.puc-rio.br
|
||||||
@ -128,6 +128,7 @@ int lua_ref (lua_State *L, int lock);
|
|||||||
** "do" functions (run Lua code)
|
** "do" functions (run Lua code)
|
||||||
*/
|
*/
|
||||||
int lua_call (lua_State *L, int nargs, int nresults);
|
int lua_call (lua_State *L, int nargs, int nresults);
|
||||||
|
void lua_rawcall (lua_State *L, int nargs, int nresults);
|
||||||
int lua_dofile (lua_State *L, const char *filename);
|
int lua_dofile (lua_State *L, const char *filename);
|
||||||
int lua_dostring (lua_State *L, const char *str);
|
int lua_dostring (lua_State *L, const char *str);
|
||||||
int lua_dobuffer (lua_State *L, const char *buff, size_t size,
|
int lua_dobuffer (lua_State *L, const char *buff, size_t size,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user