1997-09-16 23:25:59 +04:00
|
|
|
/*
|
2000-08-14 23:18:14 +04:00
|
|
|
** $Id: lapi.c,v 1.86 2000/08/09 19:16:57 roberto Exp roberto $
|
1997-09-16 23:25:59 +04:00
|
|
|
** Lua API
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2000-06-12 17:52:05 +04:00
|
|
|
#include "lua.h"
|
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
#include "lapi.h"
|
|
|
|
#include "lauxlib.h"
|
|
|
|
#include "ldo.h"
|
|
|
|
#include "lfunc.h"
|
|
|
|
#include "lgc.h"
|
|
|
|
#include "lmem.h"
|
|
|
|
#include "lobject.h"
|
1999-10-04 21:51:04 +04:00
|
|
|
#include "lref.h"
|
1997-11-19 20:29:23 +03:00
|
|
|
#include "lstate.h"
|
1997-09-16 23:25:59 +04:00
|
|
|
#include "lstring.h"
|
|
|
|
#include "ltable.h"
|
|
|
|
#include "ltm.h"
|
|
|
|
#include "lvm.h"
|
|
|
|
|
|
|
|
|
1999-08-17 00:52:00 +04:00
|
|
|
const char lua_ident[] = "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
|
1999-12-14 21:33:29 +03:00
|
|
|
"$Authors: " LUA_AUTHORS " $";
|
1997-09-16 23:25:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-03-03 17:58:26 +03:00
|
|
|
void luaA_checkCargs (lua_State *L, int nargs) {
|
|
|
|
if (nargs > L->top-L->Cstack.base)
|
|
|
|
luaL_verror(L, "Lua API error - "
|
|
|
|
"expected at least %d arguments in C2lua stack", nargs);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-14 21:33:29 +03:00
|
|
|
lua_Object luaA_putluaObject (lua_State *L, const TObject *o) {
|
1999-12-01 22:50:08 +03:00
|
|
|
luaD_openstack(L, L->Cstack.base);
|
|
|
|
*L->Cstack.base++ = *o;
|
1999-12-02 19:24:45 +03:00
|
|
|
return L->Cstack.base-1;
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
static void top2LC (lua_State *L, int n) {
|
1999-12-27 20:33:22 +03:00
|
|
|
/* Put the `n' elements on the top as the Lua2C contents */
|
1999-12-01 22:50:08 +03:00
|
|
|
L->Cstack.base = L->top; /* new base */
|
1999-02-23 17:57:28 +03:00
|
|
|
L->Cstack.lua2C = L->Cstack.base-n; /* position of the new results */
|
|
|
|
L->Cstack.num = n; /* number of results */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
lua_Object lua_pop (lua_State *L) {
|
2000-03-03 17:58:26 +03:00
|
|
|
luaA_checkCargs(L, 1);
|
2000-05-09 00:49:05 +04:00
|
|
|
if (L->Cstack.base != L->top-1) {
|
|
|
|
luaD_openstack(L, L->Cstack.base);
|
|
|
|
*L->Cstack.base = *(--L->top);
|
|
|
|
}
|
|
|
|
return L->Cstack.base++;
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-14 23:18:14 +04:00
|
|
|
void lua_pushglobals (lua_State *L) {
|
2000-06-08 22:27:13 +04:00
|
|
|
hvalue(L->top) = L->gt;
|
2000-05-08 23:32:53 +04:00
|
|
|
ttype(L->top) = TAG_TABLE;
|
|
|
|
incr_top;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-14 23:18:14 +04:00
|
|
|
void lua_setglobals (lua_State *L, lua_Object newtable) {
|
2000-05-08 23:32:53 +04:00
|
|
|
if (lua_type(L, newtable)[0] != 't') /* type == "table"? */
|
|
|
|
lua_error(L, "Lua API error - invalid value for global table");
|
2000-06-08 22:27:13 +04:00
|
|
|
L->gt = hvalue(newtable);
|
2000-05-08 23:32:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
/*
|
|
|
|
** Get a parameter, returning the object handle or LUA_NOOBJECT on error.
|
1999-12-01 22:50:08 +03:00
|
|
|
** `number' must be 1 to get the first parameter.
|
1997-09-16 23:25:59 +04:00
|
|
|
*/
|
1999-11-22 16:12:07 +03:00
|
|
|
lua_Object lua_lua2C (lua_State *L, int number) {
|
1997-11-19 20:29:23 +03:00
|
|
|
if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT;
|
1999-12-02 19:24:45 +03:00
|
|
|
return L->Cstack.lua2C+number-1;
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
int lua_callfunction (lua_State *L, lua_Object function) {
|
1997-09-16 23:25:59 +04:00
|
|
|
if (function == LUA_NOOBJECT)
|
|
|
|
return 1;
|
|
|
|
else {
|
1999-12-01 22:50:08 +03:00
|
|
|
luaD_openstack(L, L->Cstack.base);
|
2000-01-19 15:00:45 +03:00
|
|
|
*L->Cstack.base = *function;
|
1999-11-22 16:12:07 +03:00
|
|
|
return luaD_protectedrun(L);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
lua_Object lua_gettagmethod (lua_State *L, int tag, const char *event) {
|
1999-12-14 21:33:29 +03:00
|
|
|
return luaA_putluaObject(L, luaT_gettagmethod(L, tag, event));
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) {
|
1999-12-30 21:27:03 +03:00
|
|
|
TObject *method;
|
2000-03-03 17:58:26 +03:00
|
|
|
luaA_checkCargs(L, 1);
|
1999-12-30 21:27:03 +03:00
|
|
|
method = L->top-1;
|
2000-03-10 21:37:44 +03:00
|
|
|
if ((ttype(method) != TAG_NIL) && (*lua_type(L, method) != 'f'))
|
2000-03-03 17:58:26 +03:00
|
|
|
lua_error(L, "Lua API error - tag method must be a function or nil");
|
1999-12-30 21:27:03 +03:00
|
|
|
luaT_settagmethod(L, tag, event, method);
|
2000-05-09 00:49:05 +04:00
|
|
|
return lua_pop(L);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
lua_Object lua_gettable (lua_State *L) {
|
2000-03-03 17:58:26 +03:00
|
|
|
luaA_checkCargs(L, 2);
|
2000-01-24 23:14:07 +03:00
|
|
|
luaV_gettable(L, L->top--);
|
2000-05-09 00:49:05 +04:00
|
|
|
return lua_pop(L);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-26 23:17:57 +04:00
|
|
|
lua_Object lua_rawget (lua_State *L) {
|
2000-02-08 19:39:42 +03:00
|
|
|
lua_Object res;
|
2000-03-03 17:58:26 +03:00
|
|
|
luaA_checkCargs(L, 2);
|
2000-03-28 00:10:21 +04:00
|
|
|
if (ttype(L->top-2) != TAG_TABLE)
|
2000-05-26 23:17:57 +04:00
|
|
|
lua_error(L, "indexed expression not a table");
|
2000-06-08 22:27:13 +04:00
|
|
|
res = luaA_putluaObject(L, luaH_get(L, hvalue(L->top-2), L->top-1));
|
2000-02-08 19:39:42 +03:00
|
|
|
L->top -= 2;
|
|
|
|
return res;
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
void lua_settable (lua_State *L) {
|
2000-01-24 23:14:07 +03:00
|
|
|
StkId top;
|
2000-03-03 17:58:26 +03:00
|
|
|
luaA_checkCargs(L, 3);
|
2000-01-24 23:14:07 +03:00
|
|
|
top = L->top;
|
|
|
|
luaV_settable(L, top-3, top);
|
|
|
|
L->top = top-3; /* pop table, index, and value */
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-26 23:17:57 +04:00
|
|
|
void lua_rawset (lua_State *L) {
|
2000-03-03 17:58:26 +03:00
|
|
|
luaA_checkCargs(L, 3);
|
2000-05-08 23:32:53 +04:00
|
|
|
if (ttype(L->top-3) != TAG_TABLE)
|
|
|
|
lua_error(L, "indexed expression not a table");
|
2000-06-08 22:27:13 +04:00
|
|
|
*luaH_set(L, hvalue(L->top-3), L->top-2) = *(L->top-1);
|
2000-05-08 23:32:53 +04:00
|
|
|
L->top -= 3;
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
lua_Object lua_createtable (lua_State *L) {
|
1997-09-16 23:25:59 +04:00
|
|
|
TObject o;
|
1999-11-22 16:12:07 +03:00
|
|
|
luaC_checkGC(L);
|
2000-06-08 22:27:13 +04:00
|
|
|
hvalue(&o) = luaH_new(L, 0);
|
2000-03-28 00:10:21 +04:00
|
|
|
ttype(&o) = TAG_TABLE;
|
1999-12-14 21:33:29 +03:00
|
|
|
return luaA_putluaObject(L, &o);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
lua_Object lua_getglobal (lua_State *L, const char *name) {
|
2000-05-08 23:32:53 +04:00
|
|
|
luaV_getglobal(L, luaS_new(L, name), L->top++);
|
2000-05-09 00:49:05 +04:00
|
|
|
return lua_pop(L);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-08 23:32:53 +04:00
|
|
|
void lua_setglobal (lua_State *L, const char *name) {
|
|
|
|
luaA_checkCargs(L, 1);
|
|
|
|
luaV_setglobal(L, luaS_new(L, name), L->top--);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
const char *lua_type (lua_State *L, lua_Object o) {
|
1999-12-02 19:24:45 +03:00
|
|
|
UNUSED(L);
|
1999-12-14 21:33:29 +03:00
|
|
|
return (o == LUA_NOOBJECT) ? "NOOBJECT" : luaO_typename(o);
|
1999-10-07 23:04:30 +04:00
|
|
|
}
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
int lua_isnil (lua_State *L, lua_Object o) {
|
1999-12-02 19:24:45 +03:00
|
|
|
UNUSED(L);
|
2000-03-10 21:37:44 +03:00
|
|
|
return (o != LUA_NOOBJECT) && (ttype(o) == TAG_NIL);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
int lua_istable (lua_State *L, lua_Object o) {
|
1999-12-02 19:24:45 +03:00
|
|
|
UNUSED(L);
|
2000-03-28 00:10:21 +04:00
|
|
|
return (o != LUA_NOOBJECT) && (ttype(o) == TAG_TABLE);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
int lua_isuserdata (lua_State *L, lua_Object o) {
|
1999-12-02 19:24:45 +03:00
|
|
|
UNUSED(L);
|
2000-03-10 21:37:44 +03:00
|
|
|
return (o != LUA_NOOBJECT) && (ttype(o) == TAG_USERDATA);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
int lua_iscfunction (lua_State *L, lua_Object o) {
|
2000-03-30 00:19:20 +04:00
|
|
|
UNUSED(L);
|
|
|
|
return (o != LUA_NOOBJECT) && (ttype(o) == TAG_CCLOSURE);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
int lua_isnumber (lua_State *L, lua_Object o) {
|
1999-12-02 19:24:45 +03:00
|
|
|
UNUSED(L);
|
|
|
|
return (o != LUA_NOOBJECT) && (tonumber(o) == 0);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
int lua_isstring (lua_State *L, lua_Object o) {
|
1999-12-23 21:19:57 +03:00
|
|
|
UNUSED(L);
|
2000-03-10 21:37:44 +03:00
|
|
|
return (o != LUA_NOOBJECT && (ttype(o) == TAG_STRING ||
|
|
|
|
ttype(o) == TAG_NUMBER));
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
int lua_isfunction (lua_State *L, lua_Object o) {
|
1999-12-23 21:19:57 +03:00
|
|
|
return *lua_type(L, o) == 'f';
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-29 22:11:36 +03:00
|
|
|
int lua_equal(lua_State *L, lua_Object o1, lua_Object o2) {
|
1999-12-02 19:24:45 +03:00
|
|
|
UNUSED(L);
|
1999-12-23 21:19:57 +03:00
|
|
|
if (o1 == LUA_NOOBJECT || o2 == LUA_NOOBJECT)
|
|
|
|
return (o1 == o2);
|
2000-01-19 15:00:45 +03:00
|
|
|
else return luaO_equalObj(o1, o2);
|
1999-11-11 20:02:40 +03:00
|
|
|
}
|
|
|
|
|
1997-09-16 23:25:59 +04:00
|
|
|
|
1999-11-29 22:31:29 +03:00
|
|
|
double lua_getnumber (lua_State *L, lua_Object obj) {
|
1999-12-02 19:24:45 +03:00
|
|
|
UNUSED(L);
|
1999-12-23 21:19:57 +03:00
|
|
|
if (obj == LUA_NOOBJECT || tonumber(obj))
|
|
|
|
return 0.0;
|
1999-12-02 19:24:45 +03:00
|
|
|
else return (nvalue(obj));
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-29 22:31:29 +03:00
|
|
|
const char *lua_getstring (lua_State *L, lua_Object obj) {
|
1999-11-22 16:12:07 +03:00
|
|
|
luaC_checkGC(L); /* `tostring' may create a new string */
|
1999-12-02 19:24:45 +03:00
|
|
|
if (obj == LUA_NOOBJECT || tostring(L, obj))
|
1997-09-16 23:25:59 +04:00
|
|
|
return NULL;
|
1999-12-02 19:24:45 +03:00
|
|
|
else return (svalue(obj));
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
2000-05-24 17:54:49 +04:00
|
|
|
size_t lua_strlen (lua_State *L, lua_Object obj) {
|
1999-12-02 19:24:45 +03:00
|
|
|
if (obj == LUA_NOOBJECT || tostring(L, obj))
|
1998-03-06 19:54:42 +03:00
|
|
|
return 0L;
|
1999-12-02 19:24:45 +03:00
|
|
|
else return (tsvalue(obj)->u.s.len);
|
1998-03-06 19:54:42 +03:00
|
|
|
}
|
|
|
|
|
1999-11-29 22:31:29 +03:00
|
|
|
void *lua_getuserdata (lua_State *L, lua_Object obj) {
|
1999-12-02 19:24:45 +03:00
|
|
|
UNUSED(L);
|
2000-03-10 21:37:44 +03:00
|
|
|
if (obj == LUA_NOOBJECT || ttype(obj) != TAG_USERDATA)
|
1997-09-16 23:25:59 +04:00
|
|
|
return NULL;
|
1999-12-02 19:24:45 +03:00
|
|
|
else return tsvalue(obj)->u.d.value;
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-29 22:31:29 +03:00
|
|
|
lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj) {
|
|
|
|
if (!lua_iscfunction(L, obj))
|
1997-10-24 21:17:24 +04:00
|
|
|
return NULL;
|
2000-03-30 00:19:20 +04:00
|
|
|
else return clvalue(obj)->f.c;
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
void lua_pushnil (lua_State *L) {
|
2000-03-10 21:37:44 +03:00
|
|
|
ttype(L->top) = TAG_NIL;
|
1997-09-16 23:25:59 +04:00
|
|
|
incr_top;
|
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
void lua_pushnumber (lua_State *L, double n) {
|
2000-03-10 21:37:44 +03:00
|
|
|
ttype(L->top) = TAG_NUMBER;
|
1999-12-01 22:50:08 +03:00
|
|
|
nvalue(L->top) = n;
|
1997-09-16 23:25:59 +04:00
|
|
|
incr_top;
|
|
|
|
}
|
|
|
|
|
2000-05-24 17:54:49 +04:00
|
|
|
void lua_pushlstring (lua_State *L, const char *s, size_t len) {
|
1999-12-01 22:50:08 +03:00
|
|
|
tsvalue(L->top) = luaS_newlstr(L, s, len);
|
2000-03-10 21:37:44 +03:00
|
|
|
ttype(L->top) = TAG_STRING;
|
1997-09-16 23:25:59 +04:00
|
|
|
incr_top;
|
1999-11-22 16:12:07 +03:00
|
|
|
luaC_checkGC(L);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
void lua_pushstring (lua_State *L, const char *s) {
|
1998-03-06 19:54:42 +03:00
|
|
|
if (s == NULL)
|
1999-11-22 16:12:07 +03:00
|
|
|
lua_pushnil(L);
|
1998-03-06 19:54:42 +03:00
|
|
|
else
|
1999-11-22 16:12:07 +03:00
|
|
|
lua_pushlstring(L, s, strlen(s));
|
1998-03-06 19:54:42 +03:00
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
|
1997-11-27 21:25:14 +03:00
|
|
|
if (fn == NULL)
|
2000-03-03 17:58:26 +03:00
|
|
|
lua_error(L, "Lua API error - attempt to push a NULL Cfunction");
|
|
|
|
luaA_checkCargs(L, n);
|
2000-03-30 00:19:20 +04:00
|
|
|
luaV_Cclosure(L, fn, n);
|
1999-11-22 16:12:07 +03:00
|
|
|
luaC_checkGC(L);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
2000-03-20 22:14:54 +03:00
|
|
|
void lua_pushusertag (lua_State *L, void *u, int tag) { /* ORDER LUA_T */
|
|
|
|
if (tag != LUA_ANYTAG && tag != TAG_USERDATA && tag < NUM_TAGS)
|
|
|
|
luaL_verror(L, "invalid tag for a userdata (%d)", tag);
|
1999-12-01 22:50:08 +03:00
|
|
|
tsvalue(L->top) = luaS_createudata(L, u, tag);
|
2000-03-10 21:37:44 +03:00
|
|
|
ttype(L->top) = TAG_USERDATA;
|
1997-09-16 23:25:59 +04:00
|
|
|
incr_top;
|
1999-11-22 16:12:07 +03:00
|
|
|
luaC_checkGC(L);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
void luaA_pushobject (lua_State *L, const TObject *o) {
|
1999-12-01 22:50:08 +03:00
|
|
|
*L->top = *o;
|
1997-09-16 23:25:59 +04:00
|
|
|
incr_top;
|
|
|
|
}
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
void lua_pushobject (lua_State *L, lua_Object o) {
|
1997-09-16 23:25:59 +04:00
|
|
|
if (o == LUA_NOOBJECT)
|
2000-03-03 17:58:26 +03:00
|
|
|
lua_error(L, "Lua API error - attempt to push a NOOBJECT");
|
2000-01-19 15:00:45 +03:00
|
|
|
*L->top = *o;
|
1999-05-12 00:08:20 +04:00
|
|
|
incr_top;
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-02 19:24:45 +03:00
|
|
|
int lua_tag (lua_State *L, lua_Object o) {
|
|
|
|
if (o == LUA_NOOBJECT)
|
2000-03-10 21:37:44 +03:00
|
|
|
return TAG_NIL;
|
|
|
|
else if (ttype(o) == TAG_USERDATA) /* to allow `old' tags (deprecated) */
|
2000-06-08 22:27:13 +04:00
|
|
|
return tsvalue(o)->u.d.tag;
|
1999-12-23 21:19:57 +03:00
|
|
|
else
|
2000-03-20 22:14:54 +03:00
|
|
|
return luaT_effectivetag(L, o);
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
void lua_settag (lua_State *L, int tag) {
|
2000-03-03 17:58:26 +03:00
|
|
|
luaA_checkCargs(L, 1);
|
1999-11-22 16:12:07 +03:00
|
|
|
luaT_realtag(L, tag);
|
1999-12-01 22:50:08 +03:00
|
|
|
switch (ttype(L->top-1)) {
|
2000-03-28 00:10:21 +04:00
|
|
|
case TAG_TABLE:
|
2000-06-08 22:27:13 +04:00
|
|
|
hvalue(L->top-1)->htag = tag;
|
1997-09-16 23:25:59 +04:00
|
|
|
break;
|
2000-03-10 21:37:44 +03:00
|
|
|
case TAG_USERDATA:
|
2000-06-08 22:27:13 +04:00
|
|
|
tsvalue(L->top-1)->u.d.tag = tag;
|
1997-09-16 23:25:59 +04:00
|
|
|
break;
|
|
|
|
default:
|
1999-11-22 16:12:07 +03:00
|
|
|
luaL_verror(L, "cannot change the tag of a %.20s",
|
1999-12-14 21:33:29 +03:00
|
|
|
luaO_typename(L->top-1));
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
1999-12-01 22:50:08 +03:00
|
|
|
L->top--;
|
1997-09-16 23:25:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 16:12:07 +03:00
|
|
|
int luaA_next (lua_State *L, const Hash *t, int i) {
|
1999-10-14 23:13:31 +04:00
|
|
|
int tsize = t->size;
|
1999-03-01 20:49:04 +03:00
|
|
|
for (; i<tsize; i++) {
|
1999-11-23 16:58:02 +03:00
|
|
|
Node *n = node(t, i);
|
2000-03-10 21:37:44 +03:00
|
|
|
if (ttype(val(n)) != TAG_NIL) {
|
1999-11-23 16:58:02 +03:00
|
|
|
luaA_pushobject(L, key(n));
|
|
|
|
luaA_pushobject(L, val(n));
|
1999-03-01 20:49:04 +03:00
|
|
|
return i+1; /* index to be used next time */
|
|
|
|
}
|
1999-02-23 17:57:28 +03:00
|
|
|
}
|
1999-03-01 20:49:04 +03:00
|
|
|
return 0; /* no more elements */
|
1999-02-23 17:57:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-02 19:24:45 +03:00
|
|
|
int lua_next (lua_State *L, lua_Object t, int i) {
|
2000-03-28 00:10:21 +04:00
|
|
|
if (ttype(t) != TAG_TABLE)
|
2000-03-03 17:58:26 +03:00
|
|
|
lua_error(L, "Lua API error - object is not a table in `lua_next'");
|
2000-06-08 22:27:13 +04:00
|
|
|
i = luaA_next(L, hvalue(t), i);
|
1999-11-22 16:12:07 +03:00
|
|
|
top2LC(L, (i==0) ? 0 : 2);
|
1999-02-23 17:57:28 +03:00
|
|
|
return i;
|
1999-02-22 22:13:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-26 23:17:57 +04:00
|
|
|
|
|
|
|
#if LUA_DEPRECATETFUNCS
|
|
|
|
|
|
|
|
/*
|
|
|
|
** obsolete functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
lua_Object lua_rawgetglobal (lua_State *L, const char *name) {
|
2000-08-14 23:18:14 +04:00
|
|
|
lua_pushglobals(L);
|
2000-05-26 23:17:57 +04:00
|
|
|
lua_pushstring(L, name);
|
|
|
|
return lua_rawget(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lua_rawsetglobal (lua_State *L, const char *name) {
|
|
|
|
lua_Object value;
|
|
|
|
lua_beginblock(L);
|
|
|
|
value = lua_pop(L);
|
2000-08-14 23:18:14 +04:00
|
|
|
lua_pushglobals(L);
|
2000-05-26 23:17:57 +04:00
|
|
|
lua_pushstring(L, name);
|
|
|
|
lua_pushobject(L, value);
|
|
|
|
lua_rawset(L);
|
|
|
|
lua_endblock(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|