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 /lua.h | |
| 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 'lua.h')
| -rw-r--r-- | lua.h | 235 |
1 files changed, 145 insertions, 90 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.36 1999/10/07 19:04:30 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.37 1999/11/11 17:02:40 roberto Exp roberto $ |
| 3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
| 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
| 5 | ** e-mail: lua@tecgraf.puc-rio.br | 5 | ** e-mail: lua@tecgraf.puc-rio.br |
| @@ -21,144 +21,199 @@ | |||
| 21 | #define LUA_NOREF (-2) | 21 | #define LUA_NOREF (-2) |
| 22 | #define LUA_REFNIL (-1) | 22 | #define LUA_REFNIL (-1) |
| 23 | 23 | ||
| 24 | #define LUA_ANYTAG (-1) | 24 | #define LUA_ANYTAG (-1) |
| 25 | 25 | ||
| 26 | typedef struct lua_State lua_State; | 26 | typedef struct lua_State lua_State; |
| 27 | extern lua_State *lua_state; | ||
| 28 | 27 | ||
| 29 | typedef void (*lua_CFunction) (void); | 28 | typedef void (*lua_CFunction) (); |
| 30 | typedef unsigned int lua_Object; | 29 | typedef unsigned int lua_Object; |
| 31 | 30 | ||
| 32 | void lua_open (void); | 31 | lua_State *lua_newstate (void); |
| 33 | void lua_close (void); | 32 | void lua_close (lua_State *L); |
| 34 | lua_State *lua_setstate (lua_State *st); | ||
| 35 | 33 | ||
| 36 | lua_Object lua_settagmethod (int tag, const char *event); | 34 | lua_Object lua_settagmethod (lua_State *L, int tag, const char *event); |
| 37 | /* In: new method */ | 35 | /* In: new method */ |
| 38 | lua_Object lua_gettagmethod (int tag, const char *event); | 36 | lua_Object lua_gettagmethod (lua_State *L, int tag, const char *event); |
| 39 | 37 | ||
| 40 | int lua_newtag (void); | 38 | int lua_newtag (lua_State *L); |
| 41 | int lua_copytagmethods (int tagto, int tagfrom); | 39 | int lua_copytagmethods (lua_State *L, int tagto, int tagfrom); |
| 42 | void lua_settag (int tag); /* In: object */ | 40 | void lua_settag (lua_State *L, int tag); /* In: object */ |
| 43 | 41 | ||
| 44 | void lua_error (const char *s); | 42 | void lua_error (lua_State *L, const char *s); |
| 45 | int lua_dofile (const char *filename); | 43 | int lua_dofile (lua_State *L, const char *filename); |
| 46 | /* Out: returns */ | 44 | /* Out: returns */ |
| 47 | int lua_dostring (const char *string); | 45 | int lua_dostring (lua_State *L, const char *string); |
| 48 | /* Out: returns */ | 46 | /* Out: returns */ |
| 49 | int lua_dobuffer (const char *buff, int size, | 47 | int lua_dobuffer (lua_State *L, const char *buff, int size, |
| 50 | const char *name); /* Out: returns */ | 48 | const char *name); /* Out: returns */ |
| 51 | int lua_callfunction (lua_Object f); | 49 | int lua_callfunction (lua_State *L, lua_Object f); |
| 52 | /* In: parameters; Out: returns */ | 50 | /* In: parameters; Out: returns */ |
| 53 | 51 | ||
| 54 | void lua_beginblock (void); | 52 | void lua_beginblock (lua_State *L); |
| 55 | void lua_endblock (void); | 53 | void lua_endblock (lua_State *L); |
| 56 | 54 | ||
| 57 | lua_Object lua_lua2C (int number); | 55 | lua_Object lua_lua2C (lua_State *L, int number); |
| 58 | #define lua_getparam(_) lua_lua2C(_) | 56 | #define lua_getparam lua_lua2C |
| 59 | #define lua_getresult(_) lua_lua2C(_) | 57 | #define lua_getresult lua_lua2C |
| 60 | 58 | ||
| 61 | const char *lua_type (lua_Object object); | 59 | const char *lua_type (lua_State *L, lua_Object object); |
| 62 | 60 | ||
| 63 | int lua_isnil (lua_Object object); | 61 | int lua_isnil (lua_State *L, lua_Object object); |
| 64 | int lua_istable (lua_Object object); | 62 | int lua_istable (lua_State *L, lua_Object object); |
| 65 | int lua_isuserdata (lua_Object object); | 63 | int lua_isuserdata (lua_State *L, lua_Object object); |
| 66 | int lua_iscfunction (lua_Object object); | 64 | int lua_iscfunction (lua_State *L, lua_Object object); |
| 67 | int lua_isnumber (lua_Object object); | 65 | int lua_isnumber (lua_State *L, lua_Object object); |
| 68 | int lua_isstring (lua_Object object); | 66 | int lua_isstring (lua_State *L, lua_Object object); |
| 69 | int lua_isfunction (lua_Object object); | 67 | int lua_isfunction (lua_State *L, lua_Object object); |
| 70 | 68 | ||
| 71 | int lua_equalobj (lua_Object o1, lua_Object o2); | 69 | int lua_equalobj (lua_State *L, lua_Object o1, lua_Object o2); |
| 72 | 70 | ||
| 73 | double lua_getnumber (lua_Object object); | 71 | double lua_getnumber (lua_State *L, lua_Object object); |
| 74 | const char *lua_getstring (lua_Object object); | 72 | const char *lua_getstring (lua_State *L, lua_Object object); |
| 75 | long lua_strlen (lua_Object object); | 73 | long lua_strlen (lua_State *L, lua_Object object); |
| 76 | lua_CFunction lua_getcfunction (lua_Object object); | 74 | lua_CFunction lua_getcfunction (lua_State *L, lua_Object object); |
| 77 | void *lua_getuserdata (lua_Object object); | 75 | void *lua_getuserdata (lua_State *L, lua_Object object); |
| 78 | 76 | ||
| 79 | 77 | ||
| 80 | void lua_pushnil (void); | 78 | void lua_pushnil (lua_State *L); |
| 81 | void lua_pushnumber (double n); | 79 | void lua_pushnumber (lua_State *L, double n); |
| 82 | void lua_pushlstring (const char *s, long len); | 80 | void lua_pushlstring (lua_State *L, const char *s, long len); |
| 83 | void lua_pushstring (const char *s); | 81 | void lua_pushstring (lua_State *L, const char *s); |
| 84 | void lua_pushcclosure (lua_CFunction fn, int n); | 82 | void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); |
| 85 | void lua_pushusertag (void *u, int tag); | 83 | void lua_pushusertag (lua_State *L, void *u, int tag); |
| 86 | void lua_pushobject (lua_Object object); | 84 | void lua_pushobject (lua_State *L, lua_Object object); |
| 87 | 85 | ||
| 88 | lua_Object lua_pop (void); | 86 | lua_Object lua_pop (lua_State *L); |
| 89 | 87 | ||
| 90 | lua_Object lua_getglobal (const char *name); | 88 | lua_Object lua_getglobal (lua_State *L, const char *name); |
| 91 | lua_Object lua_rawgetglobal (const char *name); | 89 | lua_Object lua_rawgetglobal (lua_State *L, const char *name); |
| 92 | void lua_setglobal (const char *name); /* In: value */ | 90 | void lua_setglobal (lua_State *L, const char *name); /* In: value */ |
| 93 | void lua_rawsetglobal (const char *name); /* In: value */ | 91 | void lua_rawsetglobal (lua_State *L, const char *name);/* In: value */ |
| 94 | 92 | ||
| 95 | void lua_settable (void); /* In: table, index, value */ | 93 | void lua_settable (lua_State *L); /* In: table, index, value */ |
| 96 | void lua_rawsettable (void); /* In: table, index, value */ | 94 | void lua_rawsettable (lua_State *L); /* In: table, index, value */ |
| 97 | lua_Object lua_gettable (void); /* In: table, index */ | 95 | lua_Object lua_gettable (lua_State *L); /* In: table, index */ |
| 98 | lua_Object lua_rawgettable (void); /* In: table, index */ | 96 | lua_Object lua_rawgettable (lua_State *L); /* In: table, index */ |
| 99 | 97 | ||
| 100 | int lua_tag (lua_Object object); | 98 | int lua_tag (lua_State *L, lua_Object object); |
| 101 | 99 | ||
| 102 | const char *lua_nextvar (const char *varname); /* Out: value */ | 100 | const char *lua_nextvar (lua_State *L, const char *varname); /* Out: value */ |
| 103 | int lua_next (lua_Object o, int i); | 101 | int lua_next (lua_State *L, lua_Object o, int i); |
| 104 | /* Out: ref, value */ | 102 | /* Out: ref, value */ |
| 105 | 103 | ||
| 106 | int lua_ref (int lock); /* In: value */ | 104 | int lua_ref (lua_State *L, int lock); /* In: value */ |
| 107 | lua_Object lua_getref (int ref); | 105 | lua_Object lua_getref (lua_State *L, int ref); |
| 108 | void lua_unref (int ref); | 106 | void lua_unref (lua_State *L, int ref); |
| 109 | 107 | ||
| 110 | lua_Object lua_createtable (void); | 108 | lua_Object lua_createtable (lua_State *L); |
| 111 | 109 | ||
| 112 | long lua_collectgarbage (long limit); | 110 | long lua_collectgarbage (lua_State *L, long limit); |
| 113 | 111 | ||
| 114 | 112 | ||
| 115 | /* =============================================================== */ | 113 | lua_Object lua_seterrormethod (lua_State *L); /* In: new method */ |
| 116 | /* some useful macros/functions */ | ||
| 117 | 114 | ||
| 118 | #define lua_call(name) lua_callfunction(lua_getglobal(name)) | 115 | lua_State *lua_setstate (lua_State *st); |
| 119 | 116 | ||
| 120 | #define lua_pushref(ref) lua_pushobject(lua_getref(ref)) | ||
| 121 | 117 | ||
| 122 | #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l)) | 118 | /* |
| 119 | ** =============================================================== | ||
| 120 | ** some useful macros | ||
| 121 | ** =============================================================== | ||
| 122 | */ | ||
| 123 | 123 | ||
| 124 | #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n)) | 124 | #ifdef LUA_REENTRANT |
| 125 | 125 | ||
| 126 | #define lua_pushuserdata(u) lua_pushusertag(u, 0) | 126 | #define lua_call(L,name) lua_callfunction(L, lua_getglobal(L, name)) |
| 127 | #define lua_pushref(L,ref) lua_pushobject(L, lua_getref(L, ref)) | ||
| 128 | #define lua_refobject(L,o,l) (lua_pushobject(L, o), lua_ref(L, l)) | ||
| 129 | #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n)) | ||
| 130 | #define lua_pushuserdata(L,u) lua_pushusertag(L, u, 0) | ||
| 131 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) | ||
| 132 | #define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t)) | ||
| 127 | 133 | ||
| 128 | #define lua_pushcfunction(f) lua_pushcclosure(f, 0) | 134 | #else |
| 129 | 135 | ||
| 136 | #define lua_call(name) lua_callfunction(lua_getglobal(name)) | ||
| 137 | #define lua_pushref(ref) lua_pushobject(lua_getref(ref)) | ||
| 138 | #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l)) | ||
| 139 | #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n)) | ||
| 140 | #define lua_pushuserdata(u) lua_pushusertag(u, 0) | ||
| 141 | #define lua_pushcfunction(f) lua_pushcclosure(f, 0) | ||
| 130 | #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t)) | 142 | #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t)) |
| 131 | 143 | ||
| 132 | lua_Object lua_seterrormethod (void); /* In: new method */ | 144 | #endif |
| 133 | |||
| 134 | /* ========================================================================== | ||
| 135 | ** for compatibility with old versions. Avoid using these macros/functions | ||
| 136 | ** If your program does need any of these, define LUA_COMPAT2_5 | ||
| 137 | */ | ||
| 138 | |||
| 139 | |||
| 140 | #ifdef LUA_COMPAT2_5 | ||
| 141 | |||
| 142 | |||
| 143 | 145 | ||
| 144 | #define lua_storeglobal lua_setglobal | ||
| 145 | 146 | ||
| 146 | #define lua_lockobject(o) lua_refobject(o,1) | ||
| 147 | #define lua_lock() lua_ref(1) | ||
| 148 | #define lua_getlocked lua_getref | ||
| 149 | #define lua_pushlocked lua_pushref | ||
| 150 | #define lua_unlock lua_unref | ||
| 151 | 147 | ||
| 152 | #define lua_pushliteral(o) lua_pushstring(o) | 148 | #ifndef LUA_REENTRANT |
| 149 | /* | ||
| 150 | ** =============================================================== | ||
| 151 | ** Macros for single-state use | ||
| 152 | ** =============================================================== | ||
| 153 | */ | ||
| 153 | 154 | ||
| 154 | #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_gettable()) | 155 | extern lua_State *lua_state; |
| 155 | #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_gettable()) | ||
| 156 | 156 | ||
| 157 | #define lua_getsubscript lua_gettable | 157 | #define lua_open() ((void)(lua_state?0:(lua_state=lua_newstate()))) |
| 158 | #define lua_storesubscript lua_settable | 158 | |
| 159 | #define lua_close() (lua_close)(lua_state) | ||
| 160 | #define lua_setstate(st) (lua_setstate)(lua_state, st) | ||
| 161 | #define lua_settagmethod(tag,event) (lua_settagmethod)(lua_state, tag,event) | ||
| 162 | #define lua_gettagmethod(tag,event) (lua_gettagmethod)(lua_state, tag,event) | ||
| 163 | #define lua_newtag() (lua_newtag)(lua_state) | ||
| 164 | #define lua_copytagmethods(tagto,tagfrom) \ | ||
| 165 | (lua_copytagmethods)(lua_state, tagto,tagfrom) | ||
| 166 | #define lua_settag(tag) (lua_settag)(lua_state, tag) | ||
| 167 | #define lua_error(s) (lua_error)(lua_state, s) | ||
| 168 | #define lua_dofile(filename) (lua_dofile)(lua_state, filename) | ||
| 169 | #define lua_dostring(string) (lua_dostring)(lua_state, string) | ||
| 170 | #define lua_callfunction(f) (lua_callfunction)(lua_state, f) | ||
| 171 | #define lua_beginblock() (lua_beginblock)(lua_state) | ||
| 172 | #define lua_endblock() (lua_endblock)(lua_state) | ||
| 173 | #define lua_lua2C(number) (lua_lua2C)(lua_state, number) | ||
| 174 | #define lua_type(object) (lua_type)(lua_state, object) | ||
| 175 | #define lua_isnil(object) (lua_isnil)(lua_state, object) | ||
| 176 | #define lua_istable(object) (lua_istable)(lua_state, object) | ||
| 177 | #define lua_isuserdata(object) (lua_isuserdata)(lua_state, object) | ||
| 178 | #define lua_iscfunction(object) (lua_iscfunction)(lua_state, object) | ||
| 179 | #define lua_isnumber(object) (lua_isnumber)(lua_state, object) | ||
| 180 | #define lua_isstring(object) (lua_isstring)(lua_state, object) | ||
| 181 | #define lua_isfunction(object) (lua_isfunction)(lua_state, object) | ||
| 182 | #define lua_equalobj(o1,o2) (lua_equalobj)(lua_state, o1,o2) | ||
| 183 | #define lua_getnumber(object) (lua_getnumber)(lua_state, object) | ||
| 184 | #define lua_getstring(object) (lua_getstring)(lua_state, object) | ||
| 185 | #define lua_strlen(object) (lua_strlen)(lua_state, object) | ||
| 186 | #define lua_getcfunction(object) (lua_getcfunction)(lua_state, object) | ||
| 187 | #define lua_getuserdata(object) (lua_getuserdata)(lua_state, object) | ||
| 188 | #define lua_pushnil() (lua_pushnil)(lua_state) | ||
| 189 | #define lua_pushnumber(n) (lua_pushnumber)(lua_state, n) | ||
| 190 | #define lua_pushlstring(s,len) (lua_pushlstring)(lua_state, s,len) | ||
| 191 | #define lua_pushstring(s) (lua_pushstring)(lua_state, s) | ||
| 192 | #define lua_pushcclosure(fn,n) (lua_pushcclosure)(lua_state, fn,n) | ||
| 193 | #define lua_pushusertag(u,tag) (lua_pushusertag)(lua_state, u,tag) | ||
| 194 | #define lua_pushobject(object) (lua_pushobject)(lua_state, object) | ||
| 195 | #define lua_pop() (lua_pop)(lua_state) | ||
| 196 | #define lua_getglobal(name) (lua_getglobal)(lua_state, name) | ||
| 197 | #define lua_rawgetglobal(name) (lua_rawgetglobal)(lua_state, name) | ||
| 198 | #define lua_setglobal(name) (lua_setglobal)(lua_state, name) | ||
| 199 | #define lua_rawsetglobal(name) (lua_rawsetglobal)(lua_state, name) | ||
| 200 | #define lua_settable() (lua_settable)(lua_state) | ||
| 201 | #define lua_rawsettable() (lua_rawsettable)(lua_state) | ||
| 202 | #define lua_gettable() (lua_gettable)(lua_state) | ||
| 203 | #define lua_rawgettable() (lua_rawgettable)(lua_state) | ||
| 204 | #define lua_tag(object) (lua_tag)(lua_state, object) | ||
| 205 | #define lua_nextvar(varname) (lua_nextvar)(lua_state, varname) | ||
| 206 | #define lua_next(o,i) (lua_next)(lua_state, o,i) | ||
| 207 | #define lua_ref(lock) (lua_ref)(lua_state, lock) | ||
| 208 | #define lua_getref(ref) (lua_getref)(lua_state, ref) | ||
| 209 | #define lua_unref(ref) (lua_unref)(lua_state, ref) | ||
| 210 | #define lua_createtable() (lua_createtable)(lua_state) | ||
| 211 | #define lua_collectgarbage(limit) (lua_collectgarbage)(lua_state, limit) | ||
| 212 | #define lua_seterrormethod() (lua_seterrormethod)(lua_state) | ||
| 159 | 213 | ||
| 160 | #endif | 214 | #endif |
| 161 | 215 | ||
| 216 | |||
| 162 | #endif | 217 | #endif |
| 163 | 218 | ||
| 164 | 219 | ||
