aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 1a3031ac..9c1e6f0b 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.6 2000/09/20 12:54:17 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.7 2000/10/02 14:47:43 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -34,7 +34,7 @@ static int luaB__ALERT (lua_State *L) {
34** The library `liolib' redefines _ERRORMESSAGE for better error information. 34** The library `liolib' redefines _ERRORMESSAGE for better error information.
35*/ 35*/
36static int luaB__ERRORMESSAGE (lua_State *L) { 36static int luaB__ERRORMESSAGE (lua_State *L) {
37 luaL_checktype(L, 1, "string"); 37 luaL_checktype(L, 1, LUA_TSTRING);
38 lua_getglobal(L, LUA_ALERT); 38 lua_getglobal(L, LUA_ALERT);
39 if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */ 39 if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */
40 lua_Debug ar; 40 lua_Debug ar;
@@ -87,7 +87,7 @@ static int luaB_print (lua_State *L) {
87static int luaB_tonumber (lua_State *L) { 87static int luaB_tonumber (lua_State *L) {
88 int base = luaL_opt_int(L, 2, 10); 88 int base = luaL_opt_int(L, 2, 10);
89 if (base == 10) { /* standard conversion */ 89 if (base == 10) { /* standard conversion */
90 luaL_checktype(L, 1, "any"); 90 luaL_checkany(L, 1);
91 if (lua_isnumber(L, 1)) { 91 if (lua_isnumber(L, 1)) {
92 lua_pushnumber(L, lua_tonumber(L, 1)); 92 lua_pushnumber(L, lua_tonumber(L, 1));
93 return 1; 93 return 1;
@@ -118,7 +118,7 @@ static int luaB_error (lua_State *L) {
118} 118}
119 119
120static int luaB_setglobal (lua_State *L) { 120static int luaB_setglobal (lua_State *L) {
121 luaL_checktype(L, 2, "any"); 121 luaL_checkany(L, 2);
122 lua_setglobal(L, luaL_check_string(L, 1)); 122 lua_setglobal(L, luaL_check_string(L, 1));
123 return 0; 123 return 0;
124} 124}
@@ -129,13 +129,13 @@ static int luaB_getglobal (lua_State *L) {
129} 129}
130 130
131static int luaB_tag (lua_State *L) { 131static int luaB_tag (lua_State *L) {
132 luaL_checktype(L, 1, "any"); 132 luaL_checkany(L, 1);
133 lua_pushnumber(L, lua_tag(L, 1)); 133 lua_pushnumber(L, lua_tag(L, 1));
134 return 1; 134 return 1;
135} 135}
136 136
137static int luaB_settag (lua_State *L) { 137static int luaB_settag (lua_State *L) {
138 luaL_checktype(L, 1, "table"); 138 luaL_checktype(L, 1, LUA_TTABLE);
139 lua_pushvalue(L, 1); /* push table */ 139 lua_pushvalue(L, 1); /* push table */
140 lua_settag(L, luaL_check_int(L, 2)); 140 lua_settag(L, luaL_check_int(L, 2));
141 lua_pop(L, 1); /* remove second argument */ 141 lua_pop(L, 1); /* remove second argument */
@@ -156,7 +156,7 @@ static int luaB_copytagmethods (lua_State *L) {
156static int luaB_globals (lua_State *L) { 156static int luaB_globals (lua_State *L) {
157 lua_getglobals(L); /* value to be returned */ 157 lua_getglobals(L); /* value to be returned */
158 if (!lua_isnull(L, 1)) { 158 if (!lua_isnull(L, 1)) {
159 luaL_checktype(L, 1, "table"); 159 luaL_checktype(L, 1, LUA_TTABLE);
160 lua_pushvalue(L, 1); /* new table of globals */ 160 lua_pushvalue(L, 1); /* new table of globals */
161 lua_setglobals(L); 161 lua_setglobals(L);
162 } 162 }
@@ -164,16 +164,16 @@ static int luaB_globals (lua_State *L) {
164} 164}
165 165
166static int luaB_rawget (lua_State *L) { 166static int luaB_rawget (lua_State *L) {
167 luaL_checktype(L, 1, "table"); 167 luaL_checktype(L, 1, LUA_TTABLE);
168 luaL_checktype(L, 2, "any"); 168 luaL_checkany(L, 2);
169 lua_rawget(L, -2); 169 lua_rawget(L, -2);
170 return 1; 170 return 1;
171} 171}
172 172
173static int luaB_rawset (lua_State *L) { 173static int luaB_rawset (lua_State *L) {
174 luaL_checktype(L, 1, "table"); 174 luaL_checktype(L, 1, LUA_TTABLE);
175 luaL_checktype(L, 2, "any"); 175 luaL_checkany(L, 2);
176 luaL_checktype(L, 3, "any"); 176 luaL_checkany(L, 3);
177 lua_rawset(L, -3); 177 lua_rawset(L, -3);
178 return 1; 178 return 1;
179} 179}
@@ -209,14 +209,14 @@ static int luaB_collectgarbage (lua_State *L) {
209 209
210 210
211static int luaB_type (lua_State *L) { 211static int luaB_type (lua_State *L) {
212 luaL_checktype(L, 1, "any"); 212 luaL_checkany(L, 1);
213 lua_pushstring(L, lua_type(L, 1)); 213 lua_pushstring(L, lua_typename(L, lua_type(L, 1)));
214 return 1; 214 return 1;
215} 215}
216 216
217 217
218static int luaB_next (lua_State *L) { 218static int luaB_next (lua_State *L) {
219 luaL_checktype(L, 1, "table"); 219 luaL_checktype(L, 1, LUA_TTABLE);
220 lua_settop(L, 2); /* create a 2nd argument if there isn't one */ 220 lua_settop(L, 2); /* create a 2nd argument if there isn't one */
221 if (lua_next(L, 1)) 221 if (lua_next(L, 1))
222 return 2; 222 return 2;
@@ -269,7 +269,7 @@ static int luaB_call (lua_State *L) {
269 int err = 0; /* index of old error method */ 269 int err = 0; /* index of old error method */
270 int i, status; 270 int i, status;
271 int n; 271 int n;
272 luaL_checktype(L, 2, "table"); 272 luaL_checktype(L, 2, LUA_TTABLE);
273 n = lua_getn(L, 2); 273 n = lua_getn(L, 2);
274 if (!lua_isnull(L, 4)) { /* set new error method */ 274 if (!lua_isnull(L, 4)) { /* set new error method */
275 lua_getglobal(L, LUA_ERRORMESSAGE); 275 lua_getglobal(L, LUA_ERRORMESSAGE);
@@ -303,26 +303,26 @@ static int luaB_call (lua_State *L) {
303 303
304static int luaB_tostring (lua_State *L) { 304static int luaB_tostring (lua_State *L) {
305 char buff[64]; 305 char buff[64];
306 switch (lua_type(L, 1)[2]) { 306 switch (lua_type(L, 1)) {
307 case 'm': /* nuMber */ 307 case LUA_TNUMBER:
308 lua_pushstring(L, lua_tostring(L, 1)); 308 lua_pushstring(L, lua_tostring(L, 1));
309 return 1; 309 return 1;
310 case 'r': /* stRing */ 310 case LUA_TSTRING:
311 lua_pushvalue(L, 1); 311 lua_pushvalue(L, 1);
312 return 1; 312 return 1;
313 case 'b': /* taBle */ 313 case LUA_TTABLE:
314 sprintf(buff, "table: %p", lua_topointer(L, 1)); 314 sprintf(buff, "table: %p", lua_topointer(L, 1));
315 break; 315 break;
316 case 'n': /* fuNction */ 316 case LUA_TFUNCTION:
317 sprintf(buff, "function: %p", lua_topointer(L, 1)); 317 sprintf(buff, "function: %p", lua_topointer(L, 1));
318 break; 318 break;
319 case 'e': /* usErdata */ 319 case LUA_TUSERDATA:
320 sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1)); 320 sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1));
321 break; 321 break;
322 case 'l': /* niL */ 322 case LUA_TNIL:
323 lua_pushstring(L, "nil"); 323 lua_pushstring(L, "nil");
324 return 1; 324 return 1;
325 default: 325 case LUA_NOVALUE:
326 luaL_argerror(L, 1, "value expected"); 326 luaL_argerror(L, 1, "value expected");
327 } 327 }
328 lua_pushstring(L, buff); 328 lua_pushstring(L, buff);
@@ -332,8 +332,8 @@ static int luaB_tostring (lua_State *L) {
332 332
333static int luaB_foreachi (lua_State *L) { 333static int luaB_foreachi (lua_State *L) {
334 int n, i; 334 int n, i;
335 luaL_checktype(L, 1, "table"); 335 luaL_checktype(L, 1, LUA_TTABLE);
336 luaL_checktype(L, 2, "function"); 336 luaL_checktype(L, 2, LUA_TFUNCTION);
337 n = lua_getn(L, 1); 337 n = lua_getn(L, 1);
338 for (i=1; i<=n; i++) { 338 for (i=1; i<=n; i++) {
339 lua_pushvalue(L, 2); /* function */ 339 lua_pushvalue(L, 2); /* function */
@@ -349,8 +349,8 @@ static int luaB_foreachi (lua_State *L) {
349 349
350 350
351static int luaB_foreach (lua_State *L) { 351static int luaB_foreach (lua_State *L) {
352 luaL_checktype(L, 1, "table"); 352 luaL_checktype(L, 1, LUA_TTABLE);
353 luaL_checktype(L, 2, "function"); 353 luaL_checktype(L, 2, LUA_TFUNCTION);
354 lua_pushnil(L); /* first index */ 354 lua_pushnil(L); /* first index */
355 for (;;) { 355 for (;;) {
356 if (lua_next(L, 1) == 0) 356 if (lua_next(L, 1) == 0)
@@ -367,7 +367,7 @@ static int luaB_foreach (lua_State *L) {
367 367
368 368
369static int luaB_assert (lua_State *L) { 369static int luaB_assert (lua_State *L) {
370 luaL_checktype(L, 1, "any"); 370 luaL_checkany(L, 1);
371 if (lua_isnil(L, 1)) 371 if (lua_isnil(L, 1))
372 luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, "")); 372 luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, ""));
373 return 0; 373 return 0;
@@ -375,7 +375,7 @@ static int luaB_assert (lua_State *L) {
375 375
376 376
377static int luaB_getn (lua_State *L) { 377static int luaB_getn (lua_State *L) {
378 luaL_checktype(L, 1, "table"); 378 luaL_checktype(L, 1, LUA_TTABLE);
379 lua_pushnumber(L, lua_getn(L, 1)); 379 lua_pushnumber(L, lua_getn(L, 1));
380 return 1; 380 return 1;
381} 381}
@@ -384,7 +384,7 @@ static int luaB_getn (lua_State *L) {
384static int luaB_tinsert (lua_State *L) { 384static int luaB_tinsert (lua_State *L) {
385 int v = lua_gettop(L); /* last argument: to be inserted */ 385 int v = lua_gettop(L); /* last argument: to be inserted */
386 int n, pos; 386 int n, pos;
387 luaL_checktype(L, 1, "table"); 387 luaL_checktype(L, 1, LUA_TTABLE);
388 n = lua_getn(L, 1); 388 n = lua_getn(L, 1);
389 if (v == 2) /* called with only 2 arguments */ 389 if (v == 2) /* called with only 2 arguments */
390 pos = n+1; 390 pos = n+1;
@@ -405,7 +405,7 @@ static int luaB_tinsert (lua_State *L) {
405 405
406static int luaB_tremove (lua_State *L) { 406static int luaB_tremove (lua_State *L) {
407 int pos, n; 407 int pos, n;
408 luaL_checktype(L, 1, "table"); 408 luaL_checktype(L, 1, LUA_TTABLE);
409 n = lua_getn(L, 1); 409 n = lua_getn(L, 1);
410 pos = luaL_opt_int(L, 2, n); 410 pos = luaL_opt_int(L, 2, n);
411 if (n <= 0) return 0; /* table is "empty" */ 411 if (n <= 0) return 0; /* table is "empty" */
@@ -517,10 +517,10 @@ static void auxsort (lua_State *L, int l, int u) {
517 517
518static int luaB_sort (lua_State *L) { 518static int luaB_sort (lua_State *L) {
519 int n; 519 int n;
520 luaL_checktype(L, 1, "table"); 520 luaL_checktype(L, 1, LUA_TTABLE);
521 n = lua_getn(L, 1); 521 n = lua_getn(L, 1);
522 if (!lua_isnull(L, 2)) /* is there a 2nd argument? */ 522 if (!lua_isnull(L, 2)) /* is there a 2nd argument? */
523 luaL_checktype(L, 2, "function"); 523 luaL_checktype(L, 2, LUA_TFUNCTION);
524 lua_settop(L, 2); /* make sure there is two arguments */ 524 lua_settop(L, 2); /* make sure there is two arguments */
525 auxsort(L, 1, n); 525 auxsort(L, 1, n);
526 return 0; 526 return 0;