aboutsummaryrefslogtreecommitdiff
path: root/lbuiltin.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbuiltin.c')
-rw-r--r--lbuiltin.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/lbuiltin.c b/lbuiltin.c
index 5d6274c3..e48e1d5d 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.13 1997/11/28 12:39:45 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.14 1997/12/01 20:30:44 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*/
@@ -23,21 +23,6 @@
23 23
24 24
25 25
26static lua_Object tablearg (int arg)
27{
28 lua_Object o = lua_getparam(arg);
29 luaL_arg_check(lua_istable(o), arg, "table expected");
30 return o;
31}
32
33static lua_Object functionarg (int arg)
34{
35 lua_Object o = lua_getparam(arg);
36 luaL_arg_check(lua_isfunction(o), arg, "function expected");
37 return o;
38}
39
40
41static void pushstring (TaggedString *s) 26static void pushstring (TaggedString *s)
42{ 27{
43 TObject o; 28 TObject o;
@@ -71,7 +56,7 @@ static void nextvar (void)
71 56
72static void foreachvar (void) 57static void foreachvar (void)
73{ 58{
74 TObject f = *luaA_Address(functionarg(1)); 59 TObject f = *luaA_Address(luaL_functionarg(1));
75 GCnode *g; 60 GCnode *g;
76 StkId name = L->Cstack.base++; /* place to keep var name (to avoid GC) */ 61 StkId name = L->Cstack.base++; /* place to keep var name (to avoid GC) */
77 ttype(L->stack.stack+name) = LUA_T_NIL; 62 ttype(L->stack.stack+name) = LUA_T_NIL;
@@ -95,7 +80,7 @@ static void foreachvar (void)
95 80
96static void next (void) 81static void next (void)
97{ 82{
98 lua_Object o = tablearg(1); 83 lua_Object o = luaL_tablearg(1);
99 lua_Object r = luaL_nonnullarg(2); 84 lua_Object r = luaL_nonnullarg(2);
100 Node *n = luaH_next(luaA_Address(o), luaA_Address(r)); 85 Node *n = luaH_next(luaA_Address(o), luaA_Address(r));
101 if (n) { 86 if (n) {
@@ -107,8 +92,8 @@ static void next (void)
107 92
108static void foreach (void) 93static void foreach (void)
109{ 94{
110 TObject t = *luaA_Address(tablearg(1)); 95 TObject t = *luaA_Address(luaL_tablearg(1));
111 TObject f = *luaA_Address(functionarg(2)); 96 TObject f = *luaA_Address(luaL_functionarg(2));
112 int i; 97 int i;
113 for (i=0; i<avalue(&t)->nhash; i++) { 98 for (i=0; i<avalue(&t)->nhash; i++) {
114 Node *nd = &(avalue(&t)->node[i]); 99 Node *nd = &(avalue(&t)->node[i]);
@@ -165,7 +150,9 @@ static char *to_string (lua_Object obj)
165 } 150 }
166 case LUA_T_NIL: 151 case LUA_T_NIL:
167 return "nil"; 152 return "nil";
168 default: return "<unknown object>"; 153 default:
154 lua_error("internal error");
155 return NULL; /* to avoid warnings */
169 } 156 }
170} 157}
171 158
@@ -203,9 +190,7 @@ static void lua_obj2number (void)
203 190
204static void luaI_error (void) 191static void luaI_error (void)
205{ 192{
206 char *s = lua_getstring(lua_getparam(1)); 193 lua_error(lua_getstring(lua_getparam(1)));
207 if (s == NULL) s = "(no message)";
208 lua_error(s);
209} 194}
210 195
211 196
@@ -262,7 +247,7 @@ static int getnarg (lua_Object table)
262static void luaI_call (void) 247static void luaI_call (void)
263{ 248{
264 lua_Object f = luaL_nonnullarg(1); 249 lua_Object f = luaL_nonnullarg(1);
265 lua_Object arg = tablearg(2); 250 lua_Object arg = luaL_tablearg(2);
266 char *options = luaL_opt_string(3, ""); 251 char *options = luaL_opt_string(3, "");
267 lua_Object err = lua_getparam(4); 252 lua_Object err = lua_getparam(4);
268 int narg = getnarg(arg); 253 int narg = getnarg(arg);
@@ -302,7 +287,7 @@ static void luaI_call (void)
302 287
303static void settag (void) 288static void settag (void)
304{ 289{
305 lua_Object o = tablearg(1); 290 lua_Object o = luaL_tablearg(1);
306 lua_pushobject(o); 291 lua_pushobject(o);
307 lua_settag(luaL_check_number(2)); 292 lua_settag(luaL_check_number(2));
308} 293}
@@ -354,7 +339,7 @@ static void gettagmethod (void)
354 339
355static void seterrormethod (void) 340static void seterrormethod (void)
356{ 341{
357 lua_Object nf = functionarg(1); 342 lua_Object nf = luaL_functionarg(1);
358 lua_pushobject(nf); 343 lua_pushobject(nf);
359 lua_pushobject(lua_seterrormethod()); 344 lua_pushobject(lua_seterrormethod());
360} 345}