diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-08-28 14:57:04 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-08-28 14:57:04 -0300 |
| commit | 9fdf73bc9a6b4c6afbfff1d8181fface6b1c6761 (patch) | |
| tree | da8d97d954e5ffabf9ff275df725f1e0a3a5b3e6 /lua.h | |
| parent | f1fd9b5c2c21f24d25d7813f431a3495702ebea6 (diff) | |
| download | lua-9fdf73bc9a6b4c6afbfff1d8181fface6b1c6761.tar.gz lua-9fdf73bc9a6b4c6afbfff1d8181fface6b1c6761.tar.bz2 lua-9fdf73bc9a6b4c6afbfff1d8181fface6b1c6761.zip | |
first version for new API
Diffstat (limited to 'lua.h')
| -rw-r--r-- | lua.h | 251 |
1 files changed, 78 insertions, 173 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.58 2000/08/14 19:10:14 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.59 2000/08/17 13:18:01 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 |
| @@ -30,8 +30,10 @@ | |||
| 30 | 30 | ||
| 31 | #define LUA_ANYTAG (-1) | 31 | #define LUA_ANYTAG (-1) |
| 32 | 32 | ||
| 33 | #define LUA_MULTRET (-1) | ||
| 33 | 34 | ||
| 34 | /* error code for lua_do* */ | 35 | |
| 36 | /* error codes for lua_do* */ | ||
| 35 | #define LUA_ERRFILE 2 | 37 | #define LUA_ERRFILE 2 |
| 36 | #define LUA_ERRSYNTAX 3 | 38 | #define LUA_ERRSYNTAX 3 |
| 37 | #define LUA_ERRRUN 1 | 39 | #define LUA_ERRRUN 1 |
| @@ -40,95 +42,103 @@ | |||
| 40 | 42 | ||
| 41 | typedef struct lua_State lua_State; | 43 | typedef struct lua_State lua_State; |
| 42 | 44 | ||
| 43 | typedef void (*lua_CFunction) (lua_State *L); | 45 | typedef int (*lua_CFunction) (lua_State *L); |
| 44 | |||
| 45 | typedef struct lua_TObject *lua_Object; | ||
| 46 | |||
| 47 | #define LUA_NOOBJECT ((lua_Object)0) | ||
| 48 | 46 | ||
| 49 | 47 | ||
| 48 | /* | ||
| 49 | ** state manipulation | ||
| 50 | */ | ||
| 50 | lua_State *lua_newstate (int stacksize, int builtin); | 51 | lua_State *lua_newstate (int stacksize, int builtin); |
| 51 | void lua_close (lua_State *L); | 52 | void lua_close (lua_State *L); |
| 52 | 53 | ||
| 53 | lua_Object lua_settagmethod (lua_State *L, int tag, const char *event); | ||
| 54 | /* In: new method */ | ||
| 55 | lua_Object lua_gettagmethod (lua_State *L, int tag, const char *event); | ||
| 56 | 54 | ||
| 57 | int lua_newtag (lua_State *L); | 55 | /* |
| 58 | int lua_copytagmethods (lua_State *L, int tagto, int tagfrom); | 56 | ** basic stack manipulation |
| 59 | void lua_settag (lua_State *L, int tag); /* In: object */ | 57 | */ |
| 60 | 58 | int lua_gettop (lua_State *L); | |
| 61 | void lua_error (lua_State *L, const char *s); | 59 | void lua_settop (lua_State *L, int index); |
| 62 | int lua_dofile (lua_State *L, const char *filename); | 60 | void lua_pushobject (lua_State *L, int index); |
| 63 | /* Out: returns */ | ||
| 64 | int lua_dostring (lua_State *L, const char *str); | ||
| 65 | /* Out: returns */ | ||
| 66 | int lua_dobuffer (lua_State *L, const char *buff, size_t size, | ||
| 67 | const char *name); /* Out: returns */ | ||
| 68 | int lua_callfunction (lua_State *L, lua_Object f); | ||
| 69 | /* In: arguments; Out: returns */ | ||
| 70 | |||
| 71 | void lua_beginblock (lua_State *L); | ||
| 72 | void lua_endblock (lua_State *L); | ||
| 73 | |||
| 74 | void lua_pushglobals (lua_State *L); | ||
| 75 | void lua_setglobals (lua_State *L, lua_Object newtable); | ||
| 76 | 61 | ||
| 77 | lua_Object lua_lua2C (lua_State *L, int number); | ||
| 78 | #define lua_getparam lua_lua2C | ||
| 79 | #define lua_getresult lua_lua2C | ||
| 80 | 62 | ||
| 81 | const char *lua_type (lua_State *L, lua_Object obj); | 63 | /* |
| 64 | ** access functions (stack -> C) | ||
| 65 | */ | ||
| 82 | 66 | ||
| 83 | int lua_isnil (lua_State *L, lua_Object obj); | 67 | const char *lua_type (lua_State *L, int index); |
| 84 | int lua_istable (lua_State *L, lua_Object obj); | 68 | int lua_isnumber (lua_State *L, int index); |
| 85 | int lua_isuserdata (lua_State *L, lua_Object obj); | 69 | int lua_iscfunction (lua_State *L, int index); |
| 86 | int lua_iscfunction (lua_State *L, lua_Object obj); | 70 | int lua_tag (lua_State *L, int index); |
| 87 | int lua_isnumber (lua_State *L, lua_Object obj); | ||
| 88 | int lua_isstring (lua_State *L, lua_Object obj); | ||
| 89 | int lua_isfunction (lua_State *L, lua_Object obj); | ||
| 90 | 71 | ||
| 91 | int lua_equal (lua_State *L, lua_Object o1, lua_Object o2); | 72 | int lua_equal (lua_State *L, int index1, int index2); |
| 92 | 73 | ||
| 93 | double lua_getnumber (lua_State *L, lua_Object obj); | 74 | double lua_tonumber (lua_State *L, int index); |
| 94 | const char *lua_getstring (lua_State *L, lua_Object obj); | 75 | const char *lua_tostring (lua_State *L, int index); |
| 95 | size_t lua_strlen (lua_State *L, lua_Object obj); | 76 | size_t lua_strlen (lua_State *L, int index); |
| 96 | lua_CFunction lua_getcfunction (lua_State *L, lua_Object obj); | 77 | lua_CFunction lua_tocfunction (lua_State *L, int index); |
| 97 | void *lua_getuserdata (lua_State *L, lua_Object obj); | 78 | void *lua_touserdata (lua_State *L, int index); |
| 98 | 79 | ||
| 99 | 80 | ||
| 100 | void lua_pushnil (lua_State *L); | 81 | /* |
| 82 | ** push functions (C -> stack) | ||
| 83 | */ | ||
| 84 | void lua_pushnil (lua_State *L); | ||
| 101 | void lua_pushnumber (lua_State *L, double n); | 85 | void lua_pushnumber (lua_State *L, double n); |
| 102 | void lua_pushlstring (lua_State *L, const char *s, size_t len); | 86 | void lua_pushlstring (lua_State *L, const char *s, size_t len); |
| 103 | void lua_pushstring (lua_State *L, const char *s); | 87 | void lua_pushstring (lua_State *L, const char *s); |
| 104 | void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); | 88 | void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); |
| 105 | void lua_pushusertag (lua_State *L, void *u, int tag); | 89 | void lua_pushusertag (lua_State *L, void *u, int tag); |
| 106 | void lua_pushobject (lua_State *L, lua_Object obj); | ||
| 107 | 90 | ||
| 108 | lua_Object lua_pop (lua_State *L); | ||
| 109 | 91 | ||
| 110 | lua_Object lua_getglobal (lua_State *L, const char *name); | 92 | /* |
| 111 | void lua_setglobal (lua_State *L, const char *name); /* In: value */ | 93 | ** get functions (Lua -> stack) |
| 94 | */ | ||
| 95 | void lua_getglobal (lua_State *L, const char *name); | ||
| 96 | void lua_gettable (lua_State *L); | ||
| 97 | void lua_rawget (lua_State *L); | ||
| 98 | void lua_getglobals (lua_State *L); | ||
| 99 | void lua_gettagmethod (lua_State *L, int tag, const char *event); | ||
| 112 | 100 | ||
| 113 | void lua_settable (lua_State *L); /* In: table, index, value */ | 101 | int lua_getref (lua_State *L, int ref); |
| 114 | lua_Object lua_gettable (lua_State *L); /* In: table, index */ | ||
| 115 | 102 | ||
| 116 | void lua_rawset (lua_State *L); /* In: table, index, value */ | 103 | void lua_newtable (lua_State *L); |
| 117 | lua_Object lua_rawget (lua_State *L); /* In: table, index */ | ||
| 118 | 104 | ||
| 119 | int lua_tag (lua_State *L, lua_Object obj); | ||
| 120 | 105 | ||
| 121 | int lua_next (lua_State *L, lua_Object o, int i); | 106 | /* |
| 122 | /* Out: index, value */ | 107 | ** set functions (stack -> Lua) |
| 108 | */ | ||
| 109 | void lua_setglobal (lua_State *L, const char *name); | ||
| 110 | void lua_settable (lua_State *L); | ||
| 111 | void lua_rawset (lua_State *L); | ||
| 112 | void lua_setglobals (lua_State *L); | ||
| 113 | void lua_settagmethod (lua_State *L, int tag, const char *event); | ||
| 114 | int lua_ref (lua_State *L, int lock); | ||
| 123 | 115 | ||
| 124 | int lua_ref (lua_State *L, int lock); /* In: value */ | ||
| 125 | int lua_pushref (lua_State *L, int ref); /* Out: value */ | ||
| 126 | void lua_unref (lua_State *L, int ref); | ||
| 127 | 116 | ||
| 128 | lua_Object lua_createtable (lua_State *L); | 117 | /* |
| 118 | ** "do" functions (run Lua code) | ||
| 119 | */ | ||
| 120 | int lua_call (lua_State *L, int nargs, int nresults); | ||
| 121 | int lua_dofile (lua_State *L, const char *filename); | ||
| 122 | int lua_dostring (lua_State *L, const char *str); | ||
| 123 | int lua_dobuffer (lua_State *L, const char *buff, size_t size, | ||
| 124 | const char *name); | ||
| 125 | |||
| 126 | |||
| 127 | /* | ||
| 128 | ** miscelaneous functions | ||
| 129 | */ | ||
| 130 | int lua_newtag (lua_State *L); | ||
| 131 | int lua_copytagmethods (lua_State *L, int tagto, int tagfrom); | ||
| 132 | void lua_settag (lua_State *L, int tag); | ||
| 133 | |||
| 134 | void lua_error (lua_State *L, const char *s); | ||
| 135 | |||
| 136 | void lua_unref (lua_State *L, int ref); | ||
| 129 | 137 | ||
| 130 | long lua_collectgarbage (lua_State *L, long limit); | 138 | long lua_collectgarbage (lua_State *L, long limit); |
| 131 | 139 | ||
| 140 | int lua_next (lua_State *L, int index, int i); | ||
| 141 | |||
| 132 | 142 | ||
| 133 | 143 | ||
| 134 | /* | 144 | /* |
| @@ -137,122 +147,17 @@ long lua_collectgarbage (lua_State *L, long limit); | |||
| 137 | ** =============================================================== | 147 | ** =============================================================== |
| 138 | */ | 148 | */ |
| 139 | 149 | ||
| 140 | #ifndef LUA_SINGLESTATE | ||
| 141 | |||
| 142 | #define lua_call(L,name) lua_callfunction(L, lua_getglobal(L, name)) | ||
| 143 | #define lua_getref(L, ref) (lua_pushref(L, ref) ? lua_pop(L) : LUA_NOOBJECT) | ||
| 144 | #define lua_refobject(L,o,l) (lua_pushobject(L, o), lua_ref(L, l)) | ||
| 145 | #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n)) | 150 | #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n)) |
| 146 | #define lua_pushuserdata(L,u) lua_pushusertag(L, u, 0) | 151 | #define lua_pushuserdata(L,u) lua_pushusertag(L, u, 0) |
| 147 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) | 152 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) |
| 148 | #define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t)) | 153 | #define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t)) |
| 149 | 154 | ||
| 150 | #else | 155 | #define lua_isfunction(L,n) (*lua_type(L,n) == 'f') |
| 151 | 156 | #define lua_isstring(L,n) (lua_tostring(L,n)) | |
| 152 | #define lua_call(name) lua_callfunction(lua_getglobal(name)) | 157 | #define lua_istable(L,n) (*lua_type(L,n) == 't') |
| 153 | #define lua_getref(ref) (lua_pushref(ref) ? lua_pop() : LUA_NOOBJECT) | 158 | #define lua_isuserdata(L,n) (*lua_type(L,n) == 'u') |
| 154 | #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l)) | 159 | #define lua_isnil(L,n) (lua_type(L,n)[2] == 'l') |
| 155 | #define lua_register(n,f) (lua_pushcfunction(f), lua_setglobal(n)) | 160 | #define lua_isnull(L,n) (*lua_type(L,n) == 'N') |
| 156 | #define lua_pushuserdata(u) lua_pushusertag(u, 0) | ||
| 157 | #define lua_pushcfunction(f) lua_pushcclosure(f, 0) | ||
| 158 | #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t)) | ||
| 159 | |||
| 160 | #endif | ||
| 161 | |||
| 162 | |||
| 163 | |||
| 164 | #ifdef LUA_SINGLESTATE | ||
| 165 | /* | ||
| 166 | ** {============================================================== | ||
| 167 | ** Macros for single-state use | ||
| 168 | ** =============================================================== | ||
| 169 | */ | ||
| 170 | |||
| 171 | extern lua_State *lua_state; | ||
| 172 | |||
| 173 | #define lua_open() ((void)(lua_state?0:(lua_state=lua_newstate(0, 1)))) | ||
| 174 | |||
| 175 | #define lua_close() (lua_close)(lua_state) | ||
| 176 | #define lua_settagmethod(tag,event) (lua_settagmethod)(lua_state, tag,event) | ||
| 177 | #define lua_gettagmethod(tag,event) (lua_gettagmethod)(lua_state, tag,event) | ||
| 178 | #define lua_newtag() (lua_newtag)(lua_state) | ||
| 179 | #define lua_copytagmethods(tagto,tagfrom) \ | ||
| 180 | (lua_copytagmethods)(lua_state, tagto,tagfrom) | ||
| 181 | #define lua_settag(tag) (lua_settag)(lua_state, tag) | ||
| 182 | #define lua_error(s) (lua_error)(lua_state, s) | ||
| 183 | #define lua_dofile(filename) (lua_dofile)(lua_state, filename) | ||
| 184 | #define lua_dostring(str) (lua_dostring)(lua_state, str) | ||
| 185 | #define lua_dobuffer(b,s,n) (lua_dobuffer)(lua_state, b,s,n) | ||
| 186 | #define lua_callfunction(f) (lua_callfunction)(lua_state, f) | ||
| 187 | #define lua_beginblock() (lua_beginblock)(lua_state) | ||
| 188 | #define lua_endblock() (lua_endblock)(lua_state) | ||
| 189 | #define lua_pushglobals() (lua_pushglobals)(lua_state) | ||
| 190 | #define lua_setglobals(t) (lua_setglobals)(lua_state, t) | ||
| 191 | #define lua_lua2C(number) (lua_lua2C)(lua_state, number) | ||
| 192 | #define lua_type(obj) (lua_type)(lua_state, obj) | ||
| 193 | #define lua_isnil(obj) (lua_isnil)(lua_state, obj) | ||
| 194 | #define lua_istable(obj) (lua_istable)(lua_state, obj) | ||
| 195 | #define lua_isuserdata(obj) (lua_isuserdata)(lua_state, obj) | ||
| 196 | #define lua_iscfunction(obj) (lua_iscfunction)(lua_state, obj) | ||
| 197 | #define lua_isnumber(obj) (lua_isnumber)(lua_state, obj) | ||
| 198 | #define lua_isstring(obj) (lua_isstring)(lua_state, obj) | ||
| 199 | #define lua_isfunction(obj) (lua_isfunction)(lua_state, obj) | ||
| 200 | #define lua_equal(o1,o2) (lua_equal)(lua_state, o1,o2) | ||
| 201 | #define lua_getnumber(obj) (lua_getnumber)(lua_state, obj) | ||
| 202 | #define lua_getstring(obj) (lua_getstring)(lua_state, obj) | ||
| 203 | #define lua_strlen(obj) (lua_strlen)(lua_state, obj) | ||
| 204 | #define lua_getcfunction(obj) (lua_getcfunction)(lua_state, obj) | ||
| 205 | #define lua_getuserdata(obj) (lua_getuserdata)(lua_state, obj) | ||
| 206 | #define lua_pushnil() (lua_pushnil)(lua_state) | ||
| 207 | #define lua_pushnumber(n) (lua_pushnumber)(lua_state, n) | ||
| 208 | #define lua_pushlstring(s,len) (lua_pushlstring)(lua_state, s,len) | ||
| 209 | #define lua_pushstring(s) (lua_pushstring)(lua_state, s) | ||
| 210 | #define lua_pushusertag(u,tag) (lua_pushusertag)(lua_state, u,tag) | ||
| 211 | #define lua_pushobject(obj) (lua_pushobject)(lua_state, obj) | ||
| 212 | #define lua_pop() (lua_pop)(lua_state) | ||
| 213 | #define lua_getglobal(name) (lua_getglobal)(lua_state, name) | ||
| 214 | #define lua_setglobal(name) (lua_setglobal)(lua_state, name) | ||
| 215 | #define lua_settable() (lua_settable)(lua_state) | ||
| 216 | #define lua_gettable() (lua_gettable)(lua_state) | ||
| 217 | #define lua_rawset() (lua_rawset)(lua_state) | ||
| 218 | #define lua_rawget() (lua_rawget)(lua_state) | ||
| 219 | #define lua_tag(obj) (lua_tag)(lua_state, obj) | ||
| 220 | #define lua_next(o,i) (lua_next)(lua_state, o,i) | ||
| 221 | #define lua_ref(lock) (lua_ref)(lua_state, lock) | ||
| 222 | #define lua_pushref(ref) (lua_pushref)(lua_state, ref) | ||
| 223 | #define lua_unref(ref) (lua_unref)(lua_state, ref) | ||
| 224 | #define lua_createtable() (lua_createtable)(lua_state) | ||
| 225 | #define lua_collectgarbage(limit) (lua_collectgarbage)(lua_state, limit) | ||
| 226 | /* | ||
| 227 | ** the following typecast is a little dirty, but we know of no other | ||
| 228 | ** way to keep compatibility with old definition of `lua_CFunction' | ||
| 229 | */ | ||
| 230 | #define lua_pushcclosure(fn,n) \ | ||
| 231 | (lua_pushcclosure)(lua_state, (lua_CFunction)(fn), n) | ||
| 232 | |||
| 233 | |||
| 234 | /* | ||
| 235 | ** }============================================================== | ||
| 236 | */ | ||
| 237 | #endif | ||
| 238 | |||
| 239 | /* | ||
| 240 | ** compatibility with 3.2 | ||
| 241 | ** these functions are only available when Lua is compiled with | ||
| 242 | ** the option LUA_DEPRECATETFUNCS | ||
| 243 | */ | ||
| 244 | |||
| 245 | #define lua_rawsettable lua_rawset | ||
| 246 | #define lua_rawgettable lua_rawget | ||
| 247 | |||
| 248 | lua_Object lua_rawgetglobal (lua_State *L, const char *name); | ||
| 249 | void lua_rawsetglobal (lua_State *L, const char *name);/* In: value */ | ||
| 250 | |||
| 251 | #ifdef LUA_SINGLESTATE | ||
| 252 | #define lua_rawgetglobal(name) (lua_rawgetglobal(lua_state, name)) | ||
| 253 | #define lua_rawsetglobal(name) (lua_rawsetglobal(lua_state, name)) | ||
| 254 | #endif | ||
| 255 | |||
| 256 | 161 | ||
| 257 | #endif | 162 | #endif |
| 258 | 163 | ||
