summaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-11-28 18:13:13 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-11-28 18:13:13 -0200
commit72659a06050632da1a9b4c492302be46ac283f6b (patch)
treebac06b4ea523ba5443564d0869e392180d4b7b77 /lbaselib.c
parentdfaf8c5291fa8aef5bedbfa375853475364ac76e (diff)
downloadlua-72659a06050632da1a9b4c492302be46ac283f6b.tar.gz
lua-72659a06050632da1a9b4c492302be46ac283f6b.tar.bz2
lua-72659a06050632da1a9b4c492302be46ac283f6b.zip
no more explicit support for wide-chars; too much troble...
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c227
1 files changed, 113 insertions, 114 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 73e5c8e6..52343fe5 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.44 2001/10/17 21:12:57 roberto Exp $ 2** $Id: lbaselib.c,v 1.45 2001/10/26 17:33:30 roberto Exp $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,7 +11,6 @@
11#include <stdlib.h> 11#include <stdlib.h>
12#include <string.h> 12#include <string.h>
13 13
14#define LUA_PRIVATE
15#include "lua.h" 14#include "lua.h"
16 15
17#include "lauxlib.h" 16#include "lauxlib.h"
@@ -21,7 +20,7 @@
21 20
22 21
23static void aux_setn (lua_State *L, int t, int n) { 22static void aux_setn (lua_State *L, int t, int n) {
24 lua_pushliteral(L, l_s("n")); 23 lua_pushliteral(L, "n");
25 lua_pushnumber(L, n); 24 lua_pushnumber(L, n);
26 lua_settable(L, t); 25 lua_settable(L, t);
27} 26}
@@ -43,21 +42,21 @@ static int luaB__ALERT (lua_State *L) {
43*/ 42*/
44static int luaB__ERRORMESSAGE (lua_State *L) { 43static int luaB__ERRORMESSAGE (lua_State *L) {
45 luaL_check_rawtype(L, 1, LUA_TSTRING); 44 luaL_check_rawtype(L, 1, LUA_TSTRING);
46 lua_getglobal(L, l_s(LUA_ALERT)); 45 lua_getglobal(L, LUA_ALERT);
47 if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */ 46 if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */
48 lua_Debug ar; 47 lua_Debug ar;
49 lua_pushliteral(L, l_s("error: ")); 48 lua_pushliteral(L, "error: ");
50 lua_pushvalue(L, 1); 49 lua_pushvalue(L, 1);
51 if (lua_getstack(L, 1, &ar)) { 50 if (lua_getstack(L, 1, &ar)) {
52 lua_getinfo(L, l_s("Sl"), &ar); 51 lua_getinfo(L, "Sl", &ar);
53 if (ar.source && ar.currentline > 0) { 52 if (ar.source && ar.currentline > 0) {
54 l_char buff[100]; 53 char buff[100];
55 sprintf(buff, l_s("\n <%.70s: line %d>"), ar.short_src, ar.currentline); 54 sprintf(buff, "\n <%.70s: line %d>", ar.short_src, ar.currentline);
56 lua_pushstring(L, buff); 55 lua_pushstring(L, buff);
57 lua_concat(L, 2); 56 lua_concat(L, 2);
58 } 57 }
59 } 58 }
60 lua_pushliteral(L, l_s("\n")); 59 lua_pushliteral(L, "\n");
61 lua_concat(L, 3); 60 lua_concat(L, 3);
62 lua_rawcall(L, 1, 0); 61 lua_rawcall(L, 1, 0);
63 } 62 }
@@ -74,20 +73,20 @@ static int luaB__ERRORMESSAGE (lua_State *L) {
74static int luaB_print (lua_State *L) { 73static int luaB_print (lua_State *L) {
75 int n = lua_gettop(L); /* number of arguments */ 74 int n = lua_gettop(L); /* number of arguments */
76 int i; 75 int i;
77 lua_getglobal(L, l_s("tostring")); 76 lua_getglobal(L, "tostring");
78 for (i=1; i<=n; i++) { 77 for (i=1; i<=n; i++) {
79 const l_char *s; 78 const char *s;
80 lua_pushvalue(L, -1); /* function to be called */ 79 lua_pushvalue(L, -1); /* function to be called */
81 lua_pushvalue(L, i); /* value to print */ 80 lua_pushvalue(L, i); /* value to print */
82 lua_rawcall(L, 1, 1); 81 lua_rawcall(L, 1, 1);
83 s = lua_tostring(L, -1); /* get result */ 82 s = lua_tostring(L, -1); /* get result */
84 if (s == NULL) 83 if (s == NULL)
85 lua_error(L, l_s("`tostring' must return a string to `print'")); 84 lua_error(L, "`tostring' must return a string to `print'");
86 if (i>1) fputs(l_s("\t"), stdout); 85 if (i>1) fputs("\t", stdout);
87 fputs(s, stdout); 86 fputs(s, stdout);
88 lua_pop(L, 1); /* pop result */ 87 lua_pop(L, 1); /* pop result */
89 } 88 }
90 fputs(l_s("\n"), stdout); 89 fputs("\n", stdout);
91 return 0; 90 return 0;
92} 91}
93 92
@@ -102,14 +101,14 @@ static int luaB_tonumber (lua_State *L) {
102 } 101 }
103 } 102 }
104 else { 103 else {
105 const l_char *s1 = luaL_check_string(L, 1); 104 const char *s1 = luaL_check_string(L, 1);
106 l_char *s2; 105 char *s2;
107 unsigned long n; 106 unsigned long n;
108 luaL_arg_check(L, 2 <= base && base <= 36, 2, l_s("base out of range")); 107 luaL_arg_check(L, 2 <= base && base <= 36, 2, "base out of range");
109 n = strtoul(s1, &s2, base); 108 n = strtoul(s1, &s2, base);
110 if (s1 != s2) { /* at least one valid digit? */ 109 if (s1 != s2) { /* at least one valid digit? */
111 while (isspace(uchar(*s2))) s2++; /* skip trailing spaces */ 110 while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */
112 if (*s2 == l_c('\0')) { /* no invalid trailing characters? */ 111 if (*s2 == '\0') { /* no invalid trailing characters? */
113 lua_pushnumber(L, n); 112 lua_pushnumber(L, n);
114 return 1; 113 return 1;
115 } 114 }
@@ -143,14 +142,14 @@ static int gettag (lua_State *L, int narg) {
143 case LUA_TNUMBER: 142 case LUA_TNUMBER:
144 return (int)(lua_tonumber(L, narg)); 143 return (int)(lua_tonumber(L, narg));
145 case LUA_TSTRING: { 144 case LUA_TSTRING: {
146 const l_char *name = lua_tostring(L, narg); 145 const char *name = lua_tostring(L, narg);
147 int tag = lua_name2tag(L, name); 146 int tag = lua_name2tag(L, name);
148 if (tag == LUA_TNONE) 147 if (tag == LUA_TNONE)
149 luaL_verror(L, l_s("'%.30s' is not a valid type name"), name); 148 luaL_verror(L, "'%.30s' is not a valid type name", name);
150 return tag; 149 return tag;
151 } 150 }
152 default: 151 default:
153 luaL_argerror(L, narg, l_s("tag or type name expected")); 152 luaL_argerror(L, narg, "tag or type name expected");
154 return 0; /* to avoid warnings */ 153 return 0; /* to avoid warnings */
155 } 154 }
156} 155}
@@ -170,11 +169,11 @@ static int luaB_settype (lua_State *L) {
170} 169}
171 170
172static int luaB_weakmode (lua_State *L) { 171static int luaB_weakmode (lua_State *L) {
173 const l_char *mode = luaL_check_string(L, 2); 172 const char *mode = luaL_check_string(L, 2);
174 luaL_check_rawtype(L, 1, LUA_TTABLE); 173 luaL_check_rawtype(L, 1, LUA_TTABLE);
175 if (*mode == l_c('?')) { 174 if (*mode == '?') {
176 l_char buff[3]; 175 char buff[3];
177 l_char *s = buff; 176 char *s = buff;
178 int imode = lua_getweakmode(L, 1); 177 int imode = lua_getweakmode(L, 1);
179 if (imode & LUA_WEAK_KEY) *s++ = 'k'; 178 if (imode & LUA_WEAK_KEY) *s++ = 'k';
180 if (imode & LUA_WEAK_VALUE) *s++ = 'v'; 179 if (imode & LUA_WEAK_VALUE) *s++ = 'v';
@@ -184,8 +183,8 @@ static int luaB_weakmode (lua_State *L) {
184 } 183 }
185 else { 184 else {
186 int imode = 0; 185 int imode = 0;
187 if (strchr(mode, l_c('k'))) imode |= LUA_WEAK_KEY; 186 if (strchr(mode, 'k')) imode |= LUA_WEAK_KEY;
188 if (strchr(mode, l_c('v'))) imode |= LUA_WEAK_VALUE; 187 if (strchr(mode, 'v')) imode |= LUA_WEAK_VALUE;
189 lua_pushvalue(L, 1); /* push table */ 188 lua_pushvalue(L, 1); /* push table */
190 lua_setweakmode(L, imode); 189 lua_setweakmode(L, imode);
191 return 1; /* return the table */ 190 return 1; /* return the table */
@@ -193,7 +192,7 @@ static int luaB_weakmode (lua_State *L) {
193} 192}
194 193
195static int luaB_newtype (lua_State *L) { 194static int luaB_newtype (lua_State *L) {
196 const l_char *name = luaL_opt_string(L, 1, NULL); 195 const char *name = luaL_opt_string(L, 1, NULL);
197 lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE)); 196 lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE));
198 return 1; 197 return 1;
199} 198}
@@ -226,11 +225,11 @@ static int luaB_rawset (lua_State *L) {
226 225
227static int luaB_settagmethod (lua_State *L) { 226static int luaB_settagmethod (lua_State *L) {
228 int tag = gettag(L, 1); 227 int tag = gettag(L, 1);
229 const l_char *event = luaL_check_string(L, 2); 228 const char *event = luaL_check_string(L, 2);
230 luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3, 229 luaL_arg_check(L, lua_isfunction(L, 3) || lua_isnil(L, 3), 3,
231 l_s("function or nil expected")); 230 "function or nil expected");
232 if (strcmp(event, l_s("gc")) == 0) 231 if (strcmp(event, "gc") == 0)
233 lua_error(L, l_s("cannot set `gc' tag method from Lua")); 232 lua_error(L, "cannot set `gc' tag method from Lua");
234 lua_gettagmethod(L, tag, event); 233 lua_gettagmethod(L, tag, event);
235 lua_pushvalue(L, 3); 234 lua_pushvalue(L, 3);
236 lua_settagmethod(L, tag, event); 235 lua_settagmethod(L, tag, event);
@@ -240,9 +239,9 @@ static int luaB_settagmethod (lua_State *L) {
240 239
241static int luaB_gettagmethod (lua_State *L) { 240static int luaB_gettagmethod (lua_State *L) {
242 int tag = gettag(L, 1); 241 int tag = gettag(L, 1);
243 const l_char *event = luaL_check_string(L, 2); 242 const char *event = luaL_check_string(L, 2);
244 if (strcmp(event, l_s("gc")) == 0) 243 if (strcmp(event, "gc") == 0)
245 lua_error(L, l_s("cannot get `gc' tag method from Lua")); 244 lua_error(L, "cannot get `gc' tag method from Lua");
246 lua_gettagmethod(L, tag, event); 245 lua_gettagmethod(L, tag, event);
247 return 1; 246 return 1;
248} 247}
@@ -288,9 +287,9 @@ static int luaB_next (lua_State *L) {
288 287
289 288
290static int passresults (lua_State *L, int status, int oldtop) { 289static int passresults (lua_State *L, int status, int oldtop) {
291 static const l_char *const errornames[] = 290 static const char *const errornames[] =
292 {l_s("ok"), l_s("run-time error"), l_s("file error"), l_s("syntax error"), 291 {"ok", "run-time error", "file error", "syntax error",
293 l_s("memory error"), l_s("error in error handling")}; 292 "memory error", "error in error handling"};
294 if (status == 0) { 293 if (status == 0) {
295 int nresults = lua_gettop(L) - oldtop; 294 int nresults = lua_gettop(L) - oldtop;
296 if (nresults > 0) 295 if (nresults > 0)
@@ -311,8 +310,8 @@ static int passresults (lua_State *L, int status, int oldtop) {
311static int luaB_dostring (lua_State *L) { 310static int luaB_dostring (lua_State *L) {
312 int oldtop = lua_gettop(L); 311 int oldtop = lua_gettop(L);
313 size_t l; 312 size_t l;
314 const l_char *s = luaL_check_lstr(L, 1, &l); 313 const char *s = luaL_check_lstr(L, 1, &l);
315 const l_char *chunkname = luaL_opt_string(L, 2, s); 314 const char *chunkname = luaL_opt_string(L, 2, s);
316 return passresults(L, lua_dobuffer(L, s, l, chunkname), oldtop); 315 return passresults(L, lua_dobuffer(L, s, l, chunkname), oldtop);
317} 316}
318 317
@@ -320,36 +319,36 @@ static int luaB_dostring (lua_State *L) {
320static int luaB_loadstring (lua_State *L) { 319static int luaB_loadstring (lua_State *L) {
321 int oldtop = lua_gettop(L); 320 int oldtop = lua_gettop(L);
322 size_t l; 321 size_t l;
323 const l_char *s = luaL_check_lstr(L, 1, &l); 322 const char *s = luaL_check_lstr(L, 1, &l);
324 const l_char *chunkname = luaL_opt_string(L, 2, s); 323 const char *chunkname = luaL_opt_string(L, 2, s);
325 return passresults(L, lua_loadbuffer(L, s, l, chunkname), oldtop); 324 return passresults(L, lua_loadbuffer(L, s, l, chunkname), oldtop);
326} 325}
327 326
328static int luaB_dofile (lua_State *L) { 327static int luaB_dofile (lua_State *L) {
329 int oldtop = lua_gettop(L); 328 int oldtop = lua_gettop(L);
330 const l_char *fname = luaL_opt_string(L, 1, NULL); 329 const char *fname = luaL_opt_string(L, 1, NULL);
331 return passresults(L, lua_dofile(L, fname), oldtop); 330 return passresults(L, lua_dofile(L, fname), oldtop);
332} 331}
333 332
334 333
335static int luaB_loadfile (lua_State *L) { 334static int luaB_loadfile (lua_State *L) {
336 int oldtop = lua_gettop(L); 335 int oldtop = lua_gettop(L);
337 const l_char *fname = luaL_opt_string(L, 1, NULL); 336 const char *fname = luaL_opt_string(L, 1, NULL);
338 return passresults(L, lua_loadfile(L, fname), oldtop); 337 return passresults(L, lua_loadfile(L, fname), oldtop);
339} 338}
340 339
341 340
342 341
343#define LUA_PATH l_s("LUA_PATH") 342#define LUA_PATH "LUA_PATH"
344 343
345#define LUA_PATH_SEP l_s(";") 344#define LUA_PATH_SEP ";"
346 345
347#ifndef LUA_PATH_DEFAULT 346#ifndef LUA_PATH_DEFAULT
348#define LUA_PATH_DEFAULT l_s("./") 347#define LUA_PATH_DEFAULT "./"
349#endif 348#endif
350 349
351static int luaB_require (lua_State *L) { 350static int luaB_require (lua_State *L) {
352 const l_char *path; 351 const char *path;
353 luaL_check_string(L, 1); 352 luaL_check_string(L, 1);
354 lua_settop(L, 1); 353 lua_settop(L, 1);
355 lua_getglobal(L, LUA_PATH); /* get path */ 354 lua_getglobal(L, LUA_PATH); /* get path */
@@ -379,8 +378,8 @@ static int luaB_require (lua_State *L) {
379 if (res == 0) break; /* ok; file done */ 378 if (res == 0) break; /* ok; file done */
380 else if (res != LUA_ERRFILE) 379 else if (res != LUA_ERRFILE)
381 lua_error(L, NULL); /* error running package; propagate it */ 380 lua_error(L, NULL); /* error running package; propagate it */
382 if (*(path+l) == l_c('\0')) /* no more directories? */ 381 if (*(path+l) == '\0') /* no more directories? */
383 luaL_verror(L, l_s("could not load package `%.20s' from path `%.200s'"), 382 luaL_verror(L, "could not load package `%.20s' from path `%.200s'",
384 lua_tostring(L, 1), lua_tostring(L, 2)); 383 lua_tostring(L, 1), lua_tostring(L, 2));
385 path += l+1; /* try next directory */ 384 path += l+1; /* try next directory */
386 } 385 }
@@ -396,7 +395,7 @@ static int aux_unpack (lua_State *L, int arg) {
396 int n, i; 395 int n, i;
397 luaL_check_rawtype(L, arg, LUA_TTABLE); 396 luaL_check_rawtype(L, arg, LUA_TTABLE);
398 n = lua_getn(L, arg); 397 n = lua_getn(L, arg);
399 luaL_check_stack(L, n, l_s("table too big to unpack")); 398 luaL_check_stack(L, n, "table too big to unpack");
400 for (i=1; i<=n; i++) /* push arg[1...n] */ 399 for (i=1; i<=n; i++) /* push arg[1...n] */
401 lua_rawgeti(L, arg, i); 400 lua_rawgeti(L, arg, i);
402 return n; 401 return n;
@@ -410,15 +409,15 @@ static int luaB_unpack (lua_State *L) {
410 409
411static int luaB_call (lua_State *L) { 410static int luaB_call (lua_State *L) {
412 int oldtop; 411 int oldtop;
413 const l_char *options = luaL_opt_string(L, 3, l_s("")); 412 const char *options = luaL_opt_string(L, 3, "");
414 int err = 0; /* index of old error method */ 413 int err = 0; /* index of old error method */
415 int status; 414 int status;
416 int n; 415 int n;
417 if (!lua_isnull(L, 4)) { /* set new error method */ 416 if (!lua_isnull(L, 4)) { /* set new error method */
418 lua_getglobal(L, l_s(LUA_ERRORMESSAGE)); 417 lua_getglobal(L, LUA_ERRORMESSAGE);
419 err = lua_gettop(L); /* get index */ 418 err = lua_gettop(L); /* get index */
420 lua_pushvalue(L, 4); 419 lua_pushvalue(L, 4);
421 lua_setglobal(L, l_s(LUA_ERRORMESSAGE)); 420 lua_setglobal(L, LUA_ERRORMESSAGE);
422 } 421 }
423 oldtop = lua_gettop(L); /* top before function-call preparation */ 422 oldtop = lua_gettop(L); /* top before function-call preparation */
424 /* push function */ 423 /* push function */
@@ -427,23 +426,23 @@ static int luaB_call (lua_State *L) {
427 status = lua_call(L, n, LUA_MULTRET); 426 status = lua_call(L, n, LUA_MULTRET);
428 if (err != 0) { /* restore old error method */ 427 if (err != 0) { /* restore old error method */
429 lua_pushvalue(L, err); 428 lua_pushvalue(L, err);
430 lua_setglobal(L, l_s(LUA_ERRORMESSAGE)); 429 lua_setglobal(L, LUA_ERRORMESSAGE);
431 } 430 }
432 if (status != 0) { /* error in call? */ 431 if (status != 0) { /* error in call? */
433 if (strchr(options, l_c('x'))) 432 if (strchr(options, 'x'))
434 lua_pushnil(L); /* return nil to signal the error */ 433 lua_pushnil(L); /* return nil to signal the error */
435 else 434 else
436 lua_error(L, NULL); /* propagate error without additional messages */ 435 lua_error(L, NULL); /* propagate error without additional messages */
437 return 1; 436 return 1;
438 } 437 }
439 if (strchr(options, l_c('p'))) /* pack results? */ 438 if (strchr(options, 'p')) /* pack results? */
440 lua_error(L, l_s("obsolete option `p' in `call'")); 439 lua_error(L, "obsolete option `p' in `call'");
441 return lua_gettop(L) - oldtop; /* results are already on the stack */ 440 return lua_gettop(L) - oldtop; /* results are already on the stack */
442} 441}
443 442
444 443
445static int luaB_tostring (lua_State *L) { 444static int luaB_tostring (lua_State *L) {
446 l_char buff[64]; 445 char buff[64];
447 switch (lua_rawtag(L, 1)) { 446 switch (lua_rawtag(L, 1)) {
448 case LUA_TNUMBER: 447 case LUA_TNUMBER:
449 lua_pushstring(L, lua_tostring(L, 1)); 448 lua_pushstring(L, lua_tostring(L, 1));
@@ -452,25 +451,25 @@ static int luaB_tostring (lua_State *L) {
452 lua_pushvalue(L, 1); 451 lua_pushvalue(L, 1);
453 return 1; 452 return 1;
454 case LUA_TTABLE: 453 case LUA_TTABLE:
455 sprintf(buff, l_s("%.40s: %p"), lua_type(L, 1), lua_topointer(L, 1)); 454 sprintf(buff, "%.40s: %p", lua_type(L, 1), lua_topointer(L, 1));
456 break; 455 break;
457 case LUA_TFUNCTION: 456 case LUA_TFUNCTION:
458 sprintf(buff, l_s("function: %p"), lua_topointer(L, 1)); 457 sprintf(buff, "function: %p", lua_topointer(L, 1));
459 break; 458 break;
460 case LUA_TUSERDATA: { 459 case LUA_TUSERDATA: {
461 const l_char *t = lua_type(L, 1); 460 const char *t = lua_type(L, 1);
462 if (strcmp(t, l_s("userdata")) == 0) 461 if (strcmp(t, "userdata") == 0)
463 sprintf(buff, l_s("userdata(%d): %p"), lua_tag(L, 1), 462 sprintf(buff, "userdata(%d): %p", lua_tag(L, 1),
464 lua_touserdata(L, 1)); 463 lua_touserdata(L, 1));
465 else 464 else
466 sprintf(buff, l_s("%.40s: %p"), t, lua_touserdata(L, 1)); 465 sprintf(buff, "%.40s: %p", t, lua_touserdata(L, 1));
467 break; 466 break;
468 } 467 }
469 case LUA_TNIL: 468 case LUA_TNIL:
470 lua_pushliteral(L, l_s("nil")); 469 lua_pushliteral(L, "nil");
471 return 1; 470 return 1;
472 default: 471 default:
473 luaL_argerror(L, 1, l_s("value expected")); 472 luaL_argerror(L, 1, "value expected");
474 } 473 }
475 lua_pushstring(L, buff); 474 lua_pushstring(L, buff);
476 return 1; 475 return 1;
@@ -516,8 +515,8 @@ static int luaB_foreach (lua_State *L) {
516static int luaB_assert (lua_State *L) { 515static int luaB_assert (lua_State *L) {
517 luaL_check_any(L, 1); 516 luaL_check_any(L, 1);
518 if (lua_isnil(L, 1)) 517 if (lua_isnil(L, 1))
519 luaL_verror(L, l_s("assertion failed! %.90s"), 518 luaL_verror(L, "assertion failed! %.90s",
520 luaL_opt_string(L, 2, l_s(""))); 519 luaL_opt_string(L, 2, ""));
521 lua_settop(L, 1); 520 lua_settop(L, 1);
522 return 1; 521 return 1;
523} 522}
@@ -635,12 +634,12 @@ static void auxsort (lua_State *L, int l, int u) {
635 for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ 634 for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
636 /* repeat ++i until a[i] >= P */ 635 /* repeat ++i until a[i] >= P */
637 while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { 636 while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
638 if (i>u) lua_error(L, l_s("invalid order function for sorting")); 637 if (i>u) lua_error(L, "invalid order function for sorting");
639 lua_pop(L, 1); /* remove a[i] */ 638 lua_pop(L, 1); /* remove a[i] */
640 } 639 }
641 /* repeat --j until a[j] <= P */ 640 /* repeat --j until a[j] <= P */
642 while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { 641 while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
643 if (j<l) lua_error(L, l_s("invalid order function for sorting")); 642 if (j<l) lua_error(L, "invalid order function for sorting");
644 lua_pop(L, 1); /* remove a[j] */ 643 lua_pop(L, 1); /* remove a[j] */
645 } 644 }
646 if (j<i) { 645 if (j<i) {
@@ -680,57 +679,57 @@ static int luaB_sort (lua_State *L) {
680 679
681 680
682static const luaL_reg base_funcs[] = { 681static const luaL_reg base_funcs[] = {
683 {l_s(LUA_ALERT), luaB__ALERT}, 682 {LUA_ALERT, luaB__ALERT},
684 {l_s(LUA_ERRORMESSAGE), luaB__ERRORMESSAGE}, 683 {LUA_ERRORMESSAGE, luaB__ERRORMESSAGE},
685 {l_s("call"), luaB_call}, 684 {"call", luaB_call},
686 {l_s("collectgarbage"), luaB_collectgarbage}, 685 {"collectgarbage", luaB_collectgarbage},
687 {l_s("dofile"), luaB_dofile}, 686 {"dofile", luaB_dofile},
688 {l_s("dostring"), luaB_dostring}, 687 {"dostring", luaB_dostring},
689 {l_s("error"), luaB_error}, 688 {"error", luaB_error},
690 {l_s("foreach"), luaB_foreach}, 689 {"foreach", luaB_foreach},
691 {l_s("foreachi"), luaB_foreachi}, 690 {"foreachi", luaB_foreachi},
692 {l_s("gcinfo"), luaB_gcinfo}, 691 {"gcinfo", luaB_gcinfo},
693 {l_s("getglobal"), luaB_getglobal}, 692 {"getglobal", luaB_getglobal},
694 {l_s("gettagmethod"), luaB_gettagmethod}, 693 {"gettagmethod", luaB_gettagmethod},
695 {l_s("globals"), luaB_globals}, 694 {"globals", luaB_globals},
696 {l_s("loadfile"), luaB_loadfile}, 695 {"loadfile", luaB_loadfile},
697 {l_s("loadstring"), luaB_loadstring}, 696 {"loadstring", luaB_loadstring},
698 {l_s("newtype"), luaB_newtype}, 697 {"newtype", luaB_newtype},
699 {l_s("newtag"), luaB_newtype}, /* for compatibility 4.0 */ 698 {"newtag", luaB_newtype}, /* for compatibility 4.0 */
700 {l_s("next"), luaB_next}, 699 {"next", luaB_next},
701 {l_s("print"), luaB_print}, 700 {"print", luaB_print},
702 {l_s("rawget"), luaB_rawget}, 701 {"rawget", luaB_rawget},
703 {l_s("rawset"), luaB_rawset}, 702 {"rawset", luaB_rawset},
704 {l_s("rawgettable"), luaB_rawget}, /* for compatibility 3.2 */ 703 {"rawgettable", luaB_rawget}, /* for compatibility 3.2 */
705 {l_s("rawsettable"), luaB_rawset}, /* for compatibility 3.2 */ 704 {"rawsettable", luaB_rawset}, /* for compatibility 3.2 */
706 {l_s("rawtype"), luaB_rawtype}, 705 {"rawtype", luaB_rawtype},
707 {l_s("setglobal"), luaB_setglobal}, 706 {"setglobal", luaB_setglobal},
708 {l_s("settag"), luaB_settype}, /* for compatibility 4.0 */ 707 {"settag", luaB_settype}, /* for compatibility 4.0 */
709 {l_s("settype"), luaB_settype}, 708 {"settype", luaB_settype},
710 {l_s("settagmethod"), luaB_settagmethod}, 709 {"settagmethod", luaB_settagmethod},
711 {l_s("tag"), luaB_tag}, 710 {"tag", luaB_tag},
712 {l_s("tonumber"), luaB_tonumber}, 711 {"tonumber", luaB_tonumber},
713 {l_s("tostring"), luaB_tostring}, 712 {"tostring", luaB_tostring},
714 {l_s("type"), luaB_type}, 713 {"type", luaB_type},
715 {l_s("assert"), luaB_assert}, 714 {"assert", luaB_assert},
716 {l_s("getn"), luaB_getn}, 715 {"getn", luaB_getn},
717 {l_s("sort"), luaB_sort}, 716 {"sort", luaB_sort},
718 {l_s("tinsert"), luaB_tinsert}, 717 {"tinsert", luaB_tinsert},
719 {l_s("tremove"), luaB_tremove}, 718 {"tremove", luaB_tremove},
720 {l_s("unpack"), luaB_unpack}, 719 {"unpack", luaB_unpack},
721 {l_s("weakmode"), luaB_weakmode} 720 {"weakmode", luaB_weakmode}
722}; 721};
723 722
724 723
725 724
726LUALIB_API int lua_baselibopen (lua_State *L) { 725LUALIB_API int lua_baselibopen (lua_State *L) {
727 luaL_openl(L, base_funcs); 726 luaL_openl(L, base_funcs);
728 lua_pushliteral(L, l_s(LUA_VERSION)); 727 lua_pushliteral(L, LUA_VERSION);
729 lua_setglobal(L, l_s("_VERSION")); 728 lua_setglobal(L, "_VERSION");
730 /* `require' needs an empty table as upvalue */ 729 /* `require' needs an empty table as upvalue */
731 lua_newtable(L); 730 lua_newtable(L);
732 lua_pushcclosure(L, luaB_require, 1); 731 lua_pushcclosure(L, luaB_require, 1);
733 lua_setglobal(L, l_s("require")); 732 lua_setglobal(L, "require");
734 return 0; 733 return 0;
735} 734}
736 735