diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-11-28 18:13:13 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-11-28 18:13:13 -0200 |
commit | 72659a06050632da1a9b4c492302be46ac283f6b (patch) | |
tree | bac06b4ea523ba5443564d0869e392180d4b7b77 /lapi.c | |
parent | dfaf8c5291fa8aef5bedbfa375853475364ac76e (diff) | |
download | lua-72659a06050632da1a9b4c492302be46ac283f6b.tar.gz lua-72659a06050632da1a9b4c492302be46ac283f6b.tar.bz2 lua-72659a06050632da1a9b4c492302be46ac283f6b.zip |
no more explicit support for wide-chars; too much troble...
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 63 |
1 files changed, 31 insertions, 32 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.159 2001/10/31 19:58:11 roberto Exp $ | 2 | ** $Id: lapi.c,v 1.160 2001/11/16 16:29:51 roberto Exp $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -7,7 +7,6 @@ | |||
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | 9 | ||
10 | #define LUA_PRIVATE | ||
11 | #include "lua.h" | 10 | #include "lua.h" |
12 | 11 | ||
13 | #include "lapi.h" | 12 | #include "lapi.h" |
@@ -23,10 +22,10 @@ | |||
23 | #include "lvm.h" | 22 | #include "lvm.h" |
24 | 23 | ||
25 | 24 | ||
26 | const l_char lua_ident[] = | 25 | const char lua_ident[] = |
27 | l_s("$Lua: ") l_s(LUA_VERSION) l_s(" ") l_s(LUA_COPYRIGHT) l_s(" $\n") | 26 | "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" |
28 | l_s("$Authors: ") l_s(LUA_AUTHORS) l_s(" $\n") | 27 | "$Authors: " LUA_AUTHORS " $\n" |
29 | l_s("$URL: www.lua.org $\n"); | 28 | "$URL: www.lua.org $\n"; |
30 | 29 | ||
31 | 30 | ||
32 | 31 | ||
@@ -156,12 +155,12 @@ LUA_API int lua_rawtag (lua_State *L, int index) { | |||
156 | } | 155 | } |
157 | 156 | ||
158 | 157 | ||
159 | LUA_API const l_char *lua_type (lua_State *L, int index) { | 158 | LUA_API const char *lua_type (lua_State *L, int index) { |
160 | StkId o; | 159 | StkId o; |
161 | const l_char *type; | 160 | const char *type; |
162 | lua_lock(L); | 161 | lua_lock(L); |
163 | o = luaA_indexAcceptable(L, index); | 162 | o = luaA_indexAcceptable(L, index); |
164 | type = (o == NULL) ? l_s("no value") : luaT_typename(G(L), o); | 163 | type = (o == NULL) ? "no value" : luaT_typename(G(L), o); |
165 | lua_unlock(L); | 164 | lua_unlock(L); |
166 | return type; | 165 | return type; |
167 | } | 166 | } |
@@ -230,14 +229,14 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int index) { | |||
230 | } | 229 | } |
231 | 230 | ||
232 | 231 | ||
233 | LUA_API const l_char *lua_tostring (lua_State *L, int index) { | 232 | LUA_API const char *lua_tostring (lua_State *L, int index) { |
234 | StkId o = luaA_indexAcceptable(L, index); | 233 | StkId o = luaA_indexAcceptable(L, index); |
235 | if (o == NULL) | 234 | if (o == NULL) |
236 | return NULL; | 235 | return NULL; |
237 | else if (ttype(o) == LUA_TSTRING) | 236 | else if (ttype(o) == LUA_TSTRING) |
238 | return svalue(o); | 237 | return svalue(o); |
239 | else { | 238 | else { |
240 | const l_char *s; | 239 | const char *s; |
241 | lua_lock(L); /* `luaV_tostring' may create a new string */ | 240 | lua_lock(L); /* `luaV_tostring' may create a new string */ |
242 | s = (luaV_tostring(L, o) == 0) ? svalue(o) : NULL; | 241 | s = (luaV_tostring(L, o) == 0) ? svalue(o) : NULL; |
243 | lua_unlock(L); | 242 | lua_unlock(L); |
@@ -309,7 +308,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { | |||
309 | } | 308 | } |
310 | 309 | ||
311 | 310 | ||
312 | LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len) { | 311 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { |
313 | lua_lock(L); | 312 | lua_lock(L); |
314 | setsvalue(L->top, luaS_newlstr(L, s, len)); | 313 | setsvalue(L->top, luaS_newlstr(L, s, len)); |
315 | api_incr_top(L); | 314 | api_incr_top(L); |
@@ -317,7 +316,7 @@ LUA_API void lua_pushlstring (lua_State *L, const l_char *s, size_t len) { | |||
317 | } | 316 | } |
318 | 317 | ||
319 | 318 | ||
320 | LUA_API void lua_pushstring (lua_State *L, const l_char *s) { | 319 | LUA_API void lua_pushstring (lua_State *L, const char *s) { |
321 | if (s == NULL) | 320 | if (s == NULL) |
322 | lua_pushnil(L); | 321 | lua_pushnil(L); |
323 | else | 322 | else |
@@ -346,7 +345,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
346 | */ | 345 | */ |
347 | 346 | ||
348 | 347 | ||
349 | LUA_API void lua_getglobal (lua_State *L, const l_char *name) { | 348 | LUA_API void lua_getglobal (lua_State *L, const char *name) { |
350 | lua_lock(L); | 349 | lua_lock(L); |
351 | luaV_getglobal(L, luaS_new(L, name), L->top); | 350 | luaV_getglobal(L, luaS_new(L, name), L->top); |
352 | api_incr_top(L); | 351 | api_incr_top(L); |
@@ -398,7 +397,7 @@ LUA_API void lua_newtable (lua_State *L) { | |||
398 | */ | 397 | */ |
399 | 398 | ||
400 | 399 | ||
401 | LUA_API void lua_setglobal (lua_State *L, const l_char *name) { | 400 | LUA_API void lua_setglobal (lua_State *L, const char *name) { |
402 | lua_lock(L); | 401 | lua_lock(L); |
403 | api_checknelems(L, 1); | 402 | api_checknelems(L, 1); |
404 | luaV_setglobal(L, luaS_new(L, name), L->top - 1); | 403 | luaV_setglobal(L, luaS_new(L, name), L->top - 1); |
@@ -470,7 +469,7 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | |||
470 | } | 469 | } |
471 | 470 | ||
472 | 471 | ||
473 | LUA_API int lua_dofile (lua_State *L, const l_char *filename) { | 472 | LUA_API int lua_dofile (lua_State *L, const char *filename) { |
474 | int status; | 473 | int status; |
475 | status = lua_loadfile(L, filename); | 474 | status = lua_loadfile(L, filename); |
476 | if (status == 0) /* parse OK? */ | 475 | if (status == 0) /* parse OK? */ |
@@ -479,8 +478,8 @@ LUA_API int lua_dofile (lua_State *L, const l_char *filename) { | |||
479 | } | 478 | } |
480 | 479 | ||
481 | 480 | ||
482 | LUA_API int lua_dobuffer (lua_State *L, const l_char *buff, size_t size, | 481 | LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, |
483 | const l_char *name) { | 482 | const char *name) { |
484 | int status; | 483 | int status; |
485 | status = lua_loadbuffer(L, buff, size, name); | 484 | status = lua_loadbuffer(L, buff, size, name); |
486 | if (status == 0) /* parse OK? */ | 485 | if (status == 0) /* parse OK? */ |
@@ -489,7 +488,7 @@ LUA_API int lua_dobuffer (lua_State *L, const l_char *buff, size_t size, | |||
489 | } | 488 | } |
490 | 489 | ||
491 | 490 | ||
492 | LUA_API int lua_dostring (lua_State *L, const l_char *str) { | 491 | LUA_API int lua_dostring (lua_State *L, const char *str) { |
493 | return lua_dobuffer(L, str, strlen(str), str); | 492 | return lua_dobuffer(L, str, strlen(str), str); |
494 | } | 493 | } |
495 | 494 | ||
@@ -534,22 +533,22 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
534 | ** miscellaneous functions | 533 | ** miscellaneous functions |
535 | */ | 534 | */ |
536 | 535 | ||
537 | LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) { | 536 | LUA_API int lua_newtype (lua_State *L, const char *name, int basictype) { |
538 | int tag; | 537 | int tag; |
539 | lua_lock(L); | 538 | lua_lock(L); |
540 | if (basictype != LUA_TNONE && | 539 | if (basictype != LUA_TNONE && |
541 | basictype != LUA_TTABLE && | 540 | basictype != LUA_TTABLE && |
542 | basictype != LUA_TUSERDATA) | 541 | basictype != LUA_TUSERDATA) |
543 | luaO_verror(L, l_s("invalid basic type (%d) for new type"), basictype); | 542 | luaO_verror(L, "invalid basic type (%d) for new type", basictype); |
544 | tag = luaT_newtag(L, name, basictype); | 543 | tag = luaT_newtag(L, name, basictype); |
545 | if (tag == LUA_TNONE) | 544 | if (tag == LUA_TNONE) |
546 | luaO_verror(L, l_s("type name '%.30s' already exists"), name); | 545 | luaO_verror(L, "type name '%.30s' already exists", name); |
547 | lua_unlock(L); | 546 | lua_unlock(L); |
548 | return tag; | 547 | return tag; |
549 | } | 548 | } |
550 | 549 | ||
551 | 550 | ||
552 | LUA_API int lua_name2tag (lua_State *L, const l_char *name) { | 551 | LUA_API int lua_name2tag (lua_State *L, const char *name) { |
553 | int tag; | 552 | int tag; |
554 | const TObject *v; | 553 | const TObject *v; |
555 | lua_lock(L); | 554 | lua_lock(L); |
@@ -565,10 +564,10 @@ LUA_API int lua_name2tag (lua_State *L, const l_char *name) { | |||
565 | } | 564 | } |
566 | 565 | ||
567 | 566 | ||
568 | LUA_API const l_char *lua_tag2name (lua_State *L, int tag) { | 567 | LUA_API const char *lua_tag2name (lua_State *L, int tag) { |
569 | const l_char *s; | 568 | const char *s; |
570 | lua_lock(L); | 569 | lua_lock(L); |
571 | s = (tag == LUA_TNONE) ? l_s("no value") : typenamebytag(G(L), tag); | 570 | s = (tag == LUA_TNONE) ? "no value" : typenamebytag(G(L), tag); |
572 | lua_unlock(L); | 571 | lua_unlock(L); |
573 | return s; | 572 | return s; |
574 | } | 573 | } |
@@ -579,10 +578,10 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
579 | lua_lock(L); | 578 | lua_lock(L); |
580 | api_checknelems(L, 1); | 579 | api_checknelems(L, 1); |
581 | if (tag < 0 || tag >= G(L)->ntag) | 580 | if (tag < 0 || tag >= G(L)->ntag) |
582 | luaO_verror(L, l_s("%d is not a valid tag"), tag); | 581 | luaO_verror(L, "%d is not a valid tag", tag); |
583 | basictype = G(L)->TMtable[tag].basictype; | 582 | basictype = G(L)->TMtable[tag].basictype; |
584 | if (basictype != LUA_TNONE && basictype != ttype(L->top-1)) | 583 | if (basictype != LUA_TNONE && basictype != ttype(L->top-1)) |
585 | luaO_verror(L, l_s("tag %d can only be used for type '%.20s'"), tag, | 584 | luaO_verror(L, "tag %d can only be used for type '%.20s'", tag, |
586 | typenamebytag(G(L), basictype)); | 585 | typenamebytag(G(L), basictype)); |
587 | switch (ttype(L->top-1)) { | 586 | switch (ttype(L->top-1)) { |
588 | case LUA_TTABLE: | 587 | case LUA_TTABLE: |
@@ -592,14 +591,14 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
592 | uvalue(L->top-1)->uv.tag = tag; | 591 | uvalue(L->top-1)->uv.tag = tag; |
593 | break; | 592 | break; |
594 | default: | 593 | default: |
595 | luaO_verror(L, l_s("cannot change the tag of a %.20s"), | 594 | luaO_verror(L, "cannot change the tag of a %.20s", |
596 | luaT_typename(G(L), L->top-1)); | 595 | luaT_typename(G(L), L->top-1)); |
597 | } | 596 | } |
598 | lua_unlock(L); | 597 | lua_unlock(L); |
599 | } | 598 | } |
600 | 599 | ||
601 | 600 | ||
602 | LUA_API void lua_error (lua_State *L, const l_char *s) { | 601 | LUA_API void lua_error (lua_State *L, const char *s) { |
603 | lua_lock(L); | 602 | lua_lock(L); |
604 | luaD_error(L, s); | 603 | luaD_error(L, s); |
605 | lua_unlock(L); | 604 | lua_unlock(L); |
@@ -630,7 +629,7 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
630 | lua_lock(L); | 629 | lua_lock(L); |
631 | t = luaA_index(L, index); | 630 | t = luaA_index(L, index); |
632 | api_check(L, ttype(t) == LUA_TTABLE); | 631 | api_check(L, ttype(t) == LUA_TTABLE); |
633 | value = luaH_getstr(hvalue(t), luaS_newliteral(L, l_s("n"))); /* = t.n */ | 632 | value = luaH_getstr(hvalue(t), luaS_newliteral(L, "n")); /* = t.n */ |
634 | if (ttype(value) == LUA_TNUMBER) | 633 | if (ttype(value) == LUA_TNUMBER) |
635 | n = cast(int, nvalue(value)); | 634 | n = cast(int, nvalue(value)); |
636 | else { | 635 | else { |
@@ -734,7 +733,7 @@ LUA_API void lua_pushupvalues (lua_State *L) { | |||
734 | api_check(L, iscfunction(func)); | 733 | api_check(L, iscfunction(func)); |
735 | n = clvalue(func)->c.nupvalues; | 734 | n = clvalue(func)->c.nupvalues; |
736 | if (LUA_MINSTACK+n > lua_stackspace(L)) | 735 | if (LUA_MINSTACK+n > lua_stackspace(L)) |
737 | luaD_error(L, l_s("stack overflow")); | 736 | luaD_error(L, "stack overflow"); |
738 | for (i=0; i<n; i++) { | 737 | for (i=0; i<n; i++) { |
739 | setobj(L->top, &clvalue(func)->c.upvalue[i]); | 738 | setobj(L->top, &clvalue(func)->c.upvalue[i]); |
740 | L->top++; | 739 | L->top++; |