diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-11-22 11:12:07 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-11-22 11:12:07 -0200 |
commit | 29ede6aa13144ff7b69c57a87be1ee93f57ae896 (patch) | |
tree | adcfb5dcff7db55481cd675349e23dec0e63c939 /lauxlib.c | |
parent | 951897c09319ae5474a4b86bb7d615136577caa0 (diff) | |
download | lua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.tar.gz lua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.tar.bz2 lua-29ede6aa13144ff7b69c57a87be1ee93f57ae896.zip |
first implementation of multiple states (reentrant code).
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 75 |
1 files changed, 38 insertions, 37 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.19 1999/09/06 13:13:03 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.20 1999/10/05 18:33:43 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -14,6 +14,8 @@ | |||
14 | ** With care, these functions can be used by other libraries. | 14 | ** With care, these functions can be used by other libraries. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #define LUA_REENTRANT | ||
18 | |||
17 | #include "lauxlib.h" | 19 | #include "lauxlib.h" |
18 | #include "lua.h" | 20 | #include "lua.h" |
19 | #include "luadebug.h" | 21 | #include "luadebug.h" |
@@ -28,87 +30,86 @@ int luaL_findstring (const char *name, const char *const list[]) { | |||
28 | return -1; /* name not found */ | 30 | return -1; /* name not found */ |
29 | } | 31 | } |
30 | 32 | ||
31 | void luaL_argerror (int numarg, const char *extramsg) { | 33 | void luaL_argerror (lua_State *L, int numarg, const char *extramsg) { |
32 | lua_Function f = lua_stackedfunction(0); | 34 | lua_Function f = lua_stackedfunction(L, 0); |
33 | const char *funcname; | 35 | const char *funcname; |
34 | lua_getobjname(f, &funcname); | 36 | lua_getobjname(L, f, &funcname); |
35 | numarg -= lua_nups(f); | 37 | numarg -= lua_nups(L, f); |
36 | if (funcname == NULL) | 38 | if (funcname == NULL) |
37 | funcname = "?"; | 39 | funcname = "?"; |
38 | luaL_verror("bad argument #%d to function `%.50s' (%.100s)", | 40 | luaL_verror(L, "bad argument #%d to function `%.50s' (%.100s)", |
39 | numarg, funcname, extramsg); | 41 | numarg, funcname, extramsg); |
40 | } | 42 | } |
41 | 43 | ||
42 | static const char *checkstr (lua_Object o, int numArg, long *len) { | 44 | static const char *checkstr (lua_State *L, lua_Object o, int n, long *len) { |
43 | const char *s = lua_getstring(o); | 45 | const char *s = lua_getstring(L, o); |
44 | luaL_arg_check(s, numArg, "string expected"); | 46 | luaL_arg_check(L, s, n, "string expected"); |
45 | if (len) *len = lua_strlen(o); | 47 | if (len) *len = lua_strlen(L, o); |
46 | return s; | 48 | return s; |
47 | } | 49 | } |
48 | 50 | ||
49 | const char *luaL_check_lstr (int numArg, long *len) { | 51 | const char *luaL_check_lstr (lua_State *L, int n, long *len) { |
50 | return checkstr(lua_getparam(numArg), numArg, len); | 52 | return checkstr(L, lua_getparam(L, n), n, len); |
51 | } | 53 | } |
52 | 54 | ||
53 | const char *luaL_opt_lstr (int numArg, const char *def, long *len) { | 55 | const char *luaL_opt_lstr (lua_State *L, int n, const char *def, long *len) { |
54 | lua_Object o = lua_getparam(numArg); | 56 | lua_Object o = lua_getparam(L, n); |
55 | if (o == LUA_NOOBJECT) { | 57 | if (o == LUA_NOOBJECT) { |
56 | if (len) *len = def ? strlen(def) : 0; | 58 | if (len) *len = def ? strlen(def) : 0; |
57 | return def; | 59 | return def; |
58 | } | 60 | } |
59 | else return checkstr(o, numArg, len); | 61 | else return checkstr(L, o, n, len); |
60 | } | 62 | } |
61 | 63 | ||
62 | double luaL_check_number (int numArg) { | 64 | double luaL_check_number (lua_State *L, int n) { |
63 | lua_Object o = lua_getparam(numArg); | 65 | lua_Object o = lua_getparam(L, n); |
64 | luaL_arg_check(lua_isnumber(o), numArg, "number expected"); | 66 | luaL_arg_check(L, lua_isnumber(L, o), n, "number expected"); |
65 | return lua_getnumber(o); | 67 | return lua_getnumber(L, o); |
66 | } | 68 | } |
67 | 69 | ||
68 | 70 | ||
69 | double luaL_opt_number (int numArg, double def) { | 71 | double luaL_opt_number (lua_State *L, int n, double def) { |
70 | lua_Object o = lua_getparam(numArg); | 72 | lua_Object o = lua_getparam(L, n); |
71 | if (o == LUA_NOOBJECT) return def; | 73 | if (o == LUA_NOOBJECT) return def; |
72 | else { | 74 | else { |
73 | luaL_arg_check(lua_isnumber(o), numArg, "number expected"); | 75 | luaL_arg_check(L, lua_isnumber(L, o), n, "number expected"); |
74 | return lua_getnumber(o); | 76 | return lua_getnumber(L, o); |
75 | } | 77 | } |
76 | } | 78 | } |
77 | 79 | ||
78 | 80 | ||
79 | lua_Object luaL_tablearg (int arg) { | 81 | lua_Object luaL_tablearg (lua_State *L, int arg) { |
80 | lua_Object o = lua_getparam(arg); | 82 | lua_Object o = lua_getparam(L, arg); |
81 | luaL_arg_check(lua_istable(o), arg, "table expected"); | 83 | luaL_arg_check(L, lua_istable(L, o), arg, "table expected"); |
82 | return o; | 84 | return o; |
83 | } | 85 | } |
84 | 86 | ||
85 | lua_Object luaL_functionarg (int arg) { | 87 | lua_Object luaL_functionarg (lua_State *L, int arg) { |
86 | lua_Object o = lua_getparam(arg); | 88 | lua_Object o = lua_getparam(L, arg); |
87 | luaL_arg_check(lua_isfunction(o), arg, "function expected"); | 89 | luaL_arg_check(L, lua_isfunction(L, o), arg, "function expected"); |
88 | return o; | 90 | return o; |
89 | } | 91 | } |
90 | 92 | ||
91 | lua_Object luaL_nonnullarg (int numArg) { | 93 | lua_Object luaL_nonnullarg (lua_State *L, int n) { |
92 | lua_Object o = lua_getparam(numArg); | 94 | lua_Object o = lua_getparam(L, n); |
93 | luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected"); | 95 | luaL_arg_check(L, o != LUA_NOOBJECT, n, "value expected"); |
94 | return o; | 96 | return o; |
95 | } | 97 | } |
96 | 98 | ||
97 | void luaL_openlib (const struct luaL_reg *l, int n) { | 99 | void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n) { |
98 | int i; | 100 | int i; |
99 | lua_open(); /* make sure lua is already open */ | ||
100 | for (i=0; i<n; i++) | 101 | for (i=0; i<n; i++) |
101 | lua_register(l[i].name, l[i].func); | 102 | lua_register(L, l[i].name, l[i].func); |
102 | } | 103 | } |
103 | 104 | ||
104 | 105 | ||
105 | void luaL_verror (const char *fmt, ...) { | 106 | void luaL_verror (lua_State *L, const char *fmt, ...) { |
106 | char buff[500]; | 107 | char buff[500]; |
107 | va_list argp; | 108 | va_list argp; |
108 | va_start(argp, fmt); | 109 | va_start(argp, fmt); |
109 | vsprintf(buff, fmt, argp); | 110 | vsprintf(buff, fmt, argp); |
110 | va_end(argp); | 111 | va_end(argp); |
111 | lua_error(buff); | 112 | lua_error(L, buff); |
112 | } | 113 | } |
113 | 114 | ||
114 | 115 | ||