aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-03-03 11:58:26 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-03-03 11:58:26 -0300
commit3c9d999424520c809e05bee11d81788b488434f6 (patch)
tree7556d9ea10bda42b226aec4dd956753467cc0864 /lapi.c
parentf7840a3e0bc07813246b2bad6bf4579848187908 (diff)
downloadlua-3c9d999424520c809e05bee11d81788b488434f6.tar.gz
lua-3c9d999424520c809e05bee11d81788b488434f6.tar.bz2
lua-3c9d999424520c809e05bee11d81788b488434f6.zip
many details (most by lhf).
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/lapi.c b/lapi.c
index 01579561..d915696b 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.71 2000/02/08 16:34:31 roberto Exp roberto $ 2** $Id: lapi.c,v 1.72 2000/02/22 17:54:16 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -41,9 +41,10 @@ const TObject *luaA_protovalue (const TObject *o) {
41} 41}
42 42
43 43
44void luaA_checkCparams (lua_State *L, int nParams) { 44void luaA_checkCargs (lua_State *L, int nargs) {
45 if (nParams > L->top-L->Cstack.base) 45 if (nargs > L->top-L->Cstack.base)
46 lua_error(L, "API error - wrong number of arguments in C2lua stack"); 46 luaL_verror(L, "Lua API error - "
47 "expected at least %d arguments in C2lua stack", nargs);
47} 48}
48 49
49 50
@@ -70,7 +71,7 @@ static void top2LC (lua_State *L, int n) {
70 71
71 72
72lua_Object lua_pop (lua_State *L) { 73lua_Object lua_pop (lua_State *L) {
73 luaA_checkCparams(L, 1); 74 luaA_checkCargs(L, 1);
74 return luaA_putObjectOnTop(L); 75 return luaA_putObjectOnTop(L);
75} 76}
76 77
@@ -103,10 +104,10 @@ lua_Object lua_gettagmethod (lua_State *L, int tag, const char *event) {
103 104
104lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) { 105lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) {
105 TObject *method; 106 TObject *method;
106 luaA_checkCparams(L, 1); 107 luaA_checkCargs(L, 1);
107 method = L->top-1; 108 method = L->top-1;
108 if ((ttype(method) != LUA_T_NIL) && (*lua_type(L, method) != 'f')) 109 if ((ttype(method) != LUA_T_NIL) && (*lua_type(L, method) != 'f'))
109 lua_error(L, "API error - tag method must be a function or nil"); 110 lua_error(L, "Lua API error - tag method must be a function or nil");
110 luaT_settagmethod(L, tag, event, method); 111 luaT_settagmethod(L, tag, event, method);
111 return luaA_putObjectOnTop(L); 112 return luaA_putObjectOnTop(L);
112} 113}
@@ -114,7 +115,7 @@ lua_Object lua_settagmethod (lua_State *L, int tag, const char *event) {
114 115
115lua_Object lua_seterrormethod (lua_State *L) { 116lua_Object lua_seterrormethod (lua_State *L) {
116 lua_Object temp; 117 lua_Object temp;
117 luaA_checkCparams(L, 1); 118 luaA_checkCargs(L, 1);
118 temp = lua_getglobal(L, "_ERRORMESSAGE"); 119 temp = lua_getglobal(L, "_ERRORMESSAGE");
119 lua_setglobal(L, "_ERRORMESSAGE"); 120 lua_setglobal(L, "_ERRORMESSAGE");
120 return temp; 121 return temp;
@@ -122,7 +123,7 @@ lua_Object lua_seterrormethod (lua_State *L) {
122 123
123 124
124lua_Object lua_gettable (lua_State *L) { 125lua_Object lua_gettable (lua_State *L) {
125 luaA_checkCparams(L, 2); 126 luaA_checkCargs(L, 2);
126 luaV_gettable(L, L->top--); 127 luaV_gettable(L, L->top--);
127 return luaA_putObjectOnTop(L); 128 return luaA_putObjectOnTop(L);
128} 129}
@@ -130,7 +131,7 @@ lua_Object lua_gettable (lua_State *L) {
130 131
131lua_Object lua_rawgettable (lua_State *L) { 132lua_Object lua_rawgettable (lua_State *L) {
132 lua_Object res; 133 lua_Object res;
133 luaA_checkCparams(L, 2); 134 luaA_checkCargs(L, 2);
134 if (ttype(L->top-2) != LUA_T_ARRAY) 135 if (ttype(L->top-2) != LUA_T_ARRAY)
135 lua_error(L, "indexed expression not a table in rawgettable"); 136 lua_error(L, "indexed expression not a table in rawgettable");
136 res = luaA_putluaObject(L, luaH_get(L, avalue(L->top-2), L->top-1)); 137 res = luaA_putluaObject(L, luaH_get(L, avalue(L->top-2), L->top-1));
@@ -141,7 +142,7 @@ lua_Object lua_rawgettable (lua_State *L) {
141 142
142void lua_settable (lua_State *L) { 143void lua_settable (lua_State *L) {
143 StkId top; 144 StkId top;
144 luaA_checkCparams(L, 3); 145 luaA_checkCargs(L, 3);
145 top = L->top; 146 top = L->top;
146 luaV_settable(L, top-3, top); 147 luaV_settable(L, top-3, top);
147 L->top = top-3; /* pop table, index, and value */ 148 L->top = top-3; /* pop table, index, and value */
@@ -149,7 +150,7 @@ void lua_settable (lua_State *L) {
149 150
150 151
151void lua_rawsettable (lua_State *L) { 152void lua_rawsettable (lua_State *L) {
152 luaA_checkCparams(L, 3); 153 luaA_checkCargs(L, 3);
153 luaV_rawsettable(L, L->top-3); 154 luaV_rawsettable(L, L->top-3);
154} 155}
155 156
@@ -176,14 +177,14 @@ lua_Object lua_rawgetglobal (lua_State *L, const char *name) {
176 177
177 178
178void lua_setglobal (lua_State *L, const char *name) { 179void lua_setglobal (lua_State *L, const char *name) {
179 luaA_checkCparams(L, 1); 180 luaA_checkCargs(L, 1);
180 luaV_setglobal(L, luaS_assertglobalbyname(L, name), L->top--); 181 luaV_setglobal(L, luaS_assertglobalbyname(L, name), L->top--);
181} 182}
182 183
183 184
184void lua_rawsetglobal (lua_State *L, const char *name) { 185void lua_rawsetglobal (lua_State *L, const char *name) {
185 GlobalVar *gv = luaS_assertglobalbyname(L, name); 186 GlobalVar *gv = luaS_assertglobalbyname(L, name);
186 luaA_checkCparams(L, 1); 187 luaA_checkCargs(L, 1);
187 gv->value = *(--L->top); 188 gv->value = *(--L->top);
188} 189}
189 190
@@ -296,8 +297,8 @@ void lua_pushstring (lua_State *L, const char *s) {
296 297
297void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { 298void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
298 if (fn == NULL) 299 if (fn == NULL)
299 lua_error(L, "API error - attempt to push a NULL Cfunction"); 300 lua_error(L, "Lua API error - attempt to push a NULL Cfunction");
300 luaA_checkCparams(L, n); 301 luaA_checkCargs(L, n);
301 ttype(L->top) = LUA_T_CPROTO; 302 ttype(L->top) = LUA_T_CPROTO;
302 fvalue(L->top) = fn; 303 fvalue(L->top) = fn;
303 incr_top; 304 incr_top;
@@ -321,7 +322,7 @@ void luaA_pushobject (lua_State *L, const TObject *o) {
321 322
322void lua_pushobject (lua_State *L, lua_Object o) { 323void lua_pushobject (lua_State *L, lua_Object o) {
323 if (o == LUA_NOOBJECT) 324 if (o == LUA_NOOBJECT)
324 lua_error(L, "API error - attempt to push a NOOBJECT"); 325 lua_error(L, "Lua API error - attempt to push a NOOBJECT");
325 *L->top = *o; 326 *L->top = *o;
326 incr_top; 327 incr_top;
327} 328}
@@ -339,7 +340,7 @@ int lua_tag (lua_State *L, lua_Object o) {
339 340
340 341
341void lua_settag (lua_State *L, int tag) { 342void lua_settag (lua_State *L, int tag) {
342 luaA_checkCparams(L, 1); 343 luaA_checkCargs(L, 1);
343 luaT_realtag(L, tag); 344 luaT_realtag(L, tag);
344 switch (ttype(L->top-1)) { 345 switch (ttype(L->top-1)) {
345 case LUA_T_ARRAY: 346 case LUA_T_ARRAY:
@@ -406,7 +407,7 @@ int luaA_next (lua_State *L, const Hash *t, int i) {
406 407
407int lua_next (lua_State *L, lua_Object t, int i) { 408int lua_next (lua_State *L, lua_Object t, int i) {
408 if (ttype(t) != LUA_T_ARRAY) 409 if (ttype(t) != LUA_T_ARRAY)
409 lua_error(L, "API error - object is not a table in `lua_next'"); 410 lua_error(L, "Lua API error - object is not a table in `lua_next'");
410 i = luaA_next(L, avalue(t), i); 411 i = luaA_next(L, avalue(t), i);
411 top2LC(L, (i==0) ? 0 : 2); 412 top2LC(L, (i==0) ? 0 : 2);
412 return i; 413 return i;