aboutsummaryrefslogtreecommitdiff
path: root/lbuiltin.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbuiltin.c')
-rw-r--r--lbuiltin.c76
1 files changed, 40 insertions, 36 deletions
diff --git a/lbuiltin.c b/lbuiltin.c
index eeb3daf8..58c3e57b 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: $ 2** $Id: lbuiltin.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
3** Built-in functions 3** Built-in functions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -10,7 +10,6 @@
10#include "lapi.h" 10#include "lapi.h"
11#include "lauxlib.h" 11#include "lauxlib.h"
12#include "lbuiltin.h" 12#include "lbuiltin.h"
13#include "lglobal.h"
14#include "lmem.h" 13#include "lmem.h"
15#include "lstring.h" 14#include "lstring.h"
16#include "ltable.h" 15#include "ltable.h"
@@ -18,13 +17,25 @@
18#include "lua.h" 17#include "lua.h"
19 18
20 19
20
21static void nextvar (void) 21static void nextvar (void)
22{ 22{
23 int i = luaG_nextvar(lua_isnil(lua_getparam(1)) ? 0 : 23 lua_Object v = luaL_nonnullarg(1);
24 luaG_findsymbolbyname(luaL_check_string(1))+1); 24 TaggedString *g;
25 if (i >= 0) { 25 if (lua_isnil(v))
26 lua_pushstring(luaG_global[i].varname->str); 26 g = (TaggedString *)luaS_root.next;
27 luaA_pushobject(&s_object(i)); 27 else {
28 TObject *o = luaA_Address(v);
29 luaL_arg_check(ttype(o) == LUA_T_STRING, 1, "variable name expected");
30 g = tsvalue(o);
31 luaL_arg_check((GCnode *)g != g->head.next, 1, "variable name expected");
32 g = (TaggedString *)g->head.next;
33 }
34 while (g && g->u.globalval.ttype == LUA_T_NIL)
35 g = (TaggedString *)g->head.next;
36 if (g) {
37 lua_pushstring(g->str);
38 luaA_pushobject(&g->u.globalval);
28 } 39 }
29} 40}
30 41
@@ -32,10 +43,9 @@ static void nextvar (void)
32static void next (void) 43static void next (void)
33{ 44{
34 lua_Object o = lua_getparam(1); 45 lua_Object o = lua_getparam(1);
35 lua_Object r = lua_getparam(2); 46 lua_Object r = luaL_nonnullarg(2);
36 Node *n; 47 Node *n;
37 luaL_arg_check(lua_istable(o), 1, "table expected"); 48 luaL_arg_check(lua_istable(o), 1, "table expected");
38 luaL_arg_check(r != LUA_NOOBJECT, 2, "value expected");
39 n = luaH_next(luaA_Address(o), luaA_Address(r)); 49 n = luaH_next(luaA_Address(o), luaA_Address(r));
40 if (n) { 50 if (n) {
41 luaA_pushobject(&n->ref); 51 luaA_pushobject(&n->ref);
@@ -90,7 +100,7 @@ static char *to_string (lua_Object obj)
90 return buff; 100 return buff;
91 } 101 }
92 case LUA_T_USERDATA: { 102 case LUA_T_USERDATA: {
93 sprintf(buff, "userdata: %p", o->value.ts->u.v); 103 sprintf(buff, "userdata: %p", o->value.ts->u.d.v);
94 return buff; 104 return buff;
95 } 105 }
96 case LUA_T_NIL: 106 case LUA_T_NIL:
@@ -116,8 +126,7 @@ static void luaI_print (void)
116 126
117static void luaI_type (void) 127static void luaI_type (void)
118{ 128{
119 lua_Object o = lua_getparam(1); 129 lua_Object o = luaL_nonnullarg(1);
120 luaL_arg_check(o != LUA_NOOBJECT, 1, "no argument");
121 lua_pushstring(luaO_typenames[-ttype(luaA_Address(o))]); 130 lua_pushstring(luaO_typenames[-ttype(luaA_Address(o))]);
122 lua_pushnumber(lua_tag(o)); 131 lua_pushnumber(lua_tag(o));
123} 132}
@@ -149,8 +158,7 @@ static void luaI_assert (void)
149 158
150static void setglobal (void) 159static void setglobal (void)
151{ 160{
152 lua_Object value = lua_getparam(2); 161 lua_Object value = luaL_nonnullarg(2);
153 luaL_arg_check(value != LUA_NOOBJECT, 2, NULL);
154 lua_pushobject(value); 162 lua_pushobject(value);
155 lua_setglobal(luaL_check_string(1)); 163 lua_setglobal(luaL_check_string(1));
156 lua_pushobject(value); /* return given value */ 164 lua_pushobject(value); /* return given value */
@@ -158,8 +166,7 @@ static void setglobal (void)
158 166
159static void rawsetglobal (void) 167static void rawsetglobal (void)
160{ 168{
161 lua_Object value = lua_getparam(2); 169 lua_Object value = luaL_nonnullarg(2);
162 luaL_arg_check(value != LUA_NOOBJECT, 2, NULL);
163 lua_pushobject(value); 170 lua_pushobject(value);
164 lua_rawsetglobal(luaL_check_string(1)); 171 lua_rawsetglobal(luaL_check_string(1));
165 lua_pushobject(value); /* return given value */ 172 lua_pushobject(value); /* return given value */
@@ -233,10 +240,8 @@ static void newtag (void)
233 240
234static void rawgettable (void) 241static void rawgettable (void)
235{ 242{
236 lua_Object t = lua_getparam(1); 243 lua_Object t = luaL_nonnullarg(1);
237 lua_Object i = lua_getparam(2); 244 lua_Object i = luaL_nonnullarg(2);
238 luaL_arg_check(t != LUA_NOOBJECT, 1, NULL);
239 luaL_arg_check(i != LUA_NOOBJECT, 2, NULL);
240 lua_pushobject(t); 245 lua_pushobject(t);
241 lua_pushobject(i); 246 lua_pushobject(i);
242 lua_pushobject(lua_rawgettable()); 247 lua_pushobject(lua_rawgettable());
@@ -245,11 +250,9 @@ static void rawgettable (void)
245 250
246static void rawsettable (void) 251static void rawsettable (void)
247{ 252{
248 lua_Object t = lua_getparam(1); 253 lua_Object t = luaL_nonnullarg(1);
249 lua_Object i = lua_getparam(2); 254 lua_Object i = luaL_nonnullarg(2);
250 lua_Object v = lua_getparam(3); 255 lua_Object v = luaL_nonnullarg(3);
251 luaL_arg_check(t != LUA_NOOBJECT && i != LUA_NOOBJECT && v != LUA_NOOBJECT,
252 0, NULL);
253 lua_pushobject(t); 256 lua_pushobject(t);
254 lua_pushobject(i); 257 lua_pushobject(i);
255 lua_pushobject(v); 258 lua_pushobject(v);
@@ -259,8 +262,7 @@ static void rawsettable (void)
259 262
260static void settagmethod (void) 263static void settagmethod (void)
261{ 264{
262 lua_Object nf = lua_getparam(3); 265 lua_Object nf = luaL_nonnullarg(3);
263 luaL_arg_check(nf != LUA_NOOBJECT, 3, "value expected");
264 lua_pushobject(nf); 266 lua_pushobject(nf);
265 lua_pushobject(lua_settagmethod((int)luaL_check_number(1), 267 lua_pushobject(lua_settagmethod((int)luaL_check_number(1),
266 luaL_check_string(2))); 268 luaL_check_string(2)));
@@ -276,8 +278,7 @@ static void gettagmethod (void)
276 278
277static void seterrormethod (void) 279static void seterrormethod (void)
278{ 280{
279 lua_Object nf = lua_getparam(1); 281 lua_Object nf = luaL_nonnullarg(1);
280 luaL_arg_check(nf != LUA_NOOBJECT, 1, "value expected");
281 lua_pushobject(nf); 282 lua_pushobject(nf);
282 lua_pushobject(lua_seterrormethod()); 283 lua_pushobject(lua_seterrormethod());
283} 284}
@@ -387,18 +388,21 @@ static struct luaL_reg int_funcs[] = {
387void luaB_predefine (void) 388void luaB_predefine (void)
388{ 389{
389 int i; 390 int i;
390 Word n; 391 TaggedString *ts;
392 TObject o;
391 /* pre-register mem error messages, to avoid loop when error arises */ 393 /* pre-register mem error messages, to avoid loop when error arises */
392 luaS_newfixedstring(tableEM); 394 luaS_newfixedstring(tableEM);
393 luaS_newfixedstring(memEM); 395 luaS_newfixedstring(memEM);
396 o.ttype = LUA_T_CFUNCTION;
394 for (i=0; i<INTFUNCSIZE; i++) { 397 for (i=0; i<INTFUNCSIZE; i++) {
395 n = luaG_findsymbolbyname(int_funcs[i].name); 398 ts = luaS_new(int_funcs[i].name);
396 s_ttype(n) = LUA_T_CFUNCTION; 399 fvalue(&o) = int_funcs[i].func;
397 fvalue(&s_object(n)) = int_funcs[i].func; 400 luaS_rawsetglobal(ts, &o);
398 } 401 }
399 n = luaG_findsymbolbyname("_VERSION"); 402 ts = luaS_new("_VERSION");
400 s_ttype(n) = LUA_T_STRING; 403 ttype(&o) = LUA_T_STRING;
401 tsvalue(&s_object(n)) = luaS_new(LUA_VERSION); 404 tsvalue(&o) = luaS_new(LUA_VERSION);
405 luaS_rawsetglobal(ts, &o);
402} 406}
403 407
404 408