diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-05-31 16:41:52 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-05-31 16:41:52 -0300 |
commit | 0dfd04eb60a7b9d54a6348ef4d9a3fa3963682aa (patch) | |
tree | 7f2353754af0783c2713af728be68878f149b3ce | |
parent | 1e0aaf2156bb261787606b8cf00f812d75344ff2 (diff) | |
download | lua-0dfd04eb60a7b9d54a6348ef4d9a3fa3963682aa.tar.gz lua-0dfd04eb60a7b9d54a6348ef4d9a3fa3963682aa.tar.bz2 lua-0dfd04eb60a7b9d54a6348ef4d9a3fa3963682aa.zip |
`lua_strlen' upgraded to `lua_objsize' (which also works with userdata)
-rw-r--r-- | lapi.c | 6 | ||||
-rw-r--r-- | ltests.c | 17 | ||||
-rw-r--r-- | lua.h | 11 |
3 files changed, 11 insertions, 23 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.8 2004/05/11 16:52:08 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.9 2004/05/14 19:25:09 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -323,10 +323,12 @@ LUA_API const char *lua_tostring (lua_State *L, int idx) { | |||
323 | } | 323 | } |
324 | 324 | ||
325 | 325 | ||
326 | LUA_API size_t lua_strlen (lua_State *L, int idx) { | 326 | LUA_API size_t lua_objsize (lua_State *L, int idx) { |
327 | StkId o = luaA_index(L, idx); | 327 | StkId o = luaA_index(L, idx); |
328 | if (ttisstring(o)) | 328 | if (ttisstring(o)) |
329 | return tsvalue(o)->len; | 329 | return tsvalue(o)->len; |
330 | else if (ttisuserdata(o)) | ||
331 | return uvalue(o)->len; | ||
330 | else { | 332 | else { |
331 | size_t l; | 333 | size_t l; |
332 | lua_lock(L); /* `luaV_tostring' may create a new string */ | 334 | lua_lock(L); /* `luaV_tostring' may create a new string */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.6 2004/05/10 17:50:51 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.7 2004/05/31 18:50:48 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -760,16 +760,6 @@ static int int2fb_aux (lua_State *L) { | |||
760 | } | 760 | } |
761 | 761 | ||
762 | 762 | ||
763 | static int test_do (lua_State *L) { | ||
764 | const char *p = luaL_checkstring(L, 1); | ||
765 | if (*p == '@') | ||
766 | lua_dofile(L, p+1); | ||
767 | else | ||
768 | lua_dostring(L, p); | ||
769 | return lua_gettop(L); | ||
770 | } | ||
771 | |||
772 | |||
773 | 763 | ||
774 | /* | 764 | /* |
775 | ** {====================================================== | 765 | ** {====================================================== |
@@ -858,8 +848,8 @@ static int testC (lua_State *L) { | |||
858 | const char *s = lua_tostring(L, getnum); | 848 | const char *s = lua_tostring(L, getnum); |
859 | lua_pushstring(L, s); | 849 | lua_pushstring(L, s); |
860 | } | 850 | } |
861 | else if EQ("strlen") { | 851 | else if EQ("objsize") { |
862 | lua_pushinteger(L, lua_strlen(L, getnum)); | 852 | lua_pushinteger(L, lua_objsize(L, getnum)); |
863 | } | 853 | } |
864 | else if EQ("tocfunction") { | 854 | else if EQ("tocfunction") { |
865 | lua_pushcfunction(L, lua_tocfunction(L, getnum)); | 855 | lua_pushcfunction(L, lua_tocfunction(L, getnum)); |
@@ -1033,7 +1023,6 @@ static const struct luaL_reg tests_funcs[] = { | |||
1033 | {"stacklevel", stacklevel}, | 1023 | {"stacklevel", stacklevel}, |
1034 | {"querystr", string_query}, | 1024 | {"querystr", string_query}, |
1035 | {"querytab", table_query}, | 1025 | {"querytab", table_query}, |
1036 | {"doit", test_do}, | ||
1037 | {"testC", testC}, | 1026 | {"testC", testC}, |
1038 | {"checkmemory", lua_checkmemory}, | 1027 | {"checkmemory", lua_checkmemory}, |
1039 | {"gccolor", get_gccolor}, | 1028 | {"gccolor", get_gccolor}, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.188 2004/03/24 13:55:46 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.189 2004/04/30 20:13:38 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil | 4 | ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil |
5 | ** http://www.lua.org mailto:info@lua.org | 5 | ** http://www.lua.org mailto:info@lua.org |
@@ -145,7 +145,7 @@ LUA_API lua_Number lua_tonumber (lua_State *L, int idx); | |||
145 | LUA_API lua_Integer lua_tointeger (lua_State *L, int idx); | 145 | LUA_API lua_Integer lua_tointeger (lua_State *L, int idx); |
146 | LUA_API int lua_toboolean (lua_State *L, int idx); | 146 | LUA_API int lua_toboolean (lua_State *L, int idx); |
147 | LUA_API const char *lua_tostring (lua_State *L, int idx); | 147 | LUA_API const char *lua_tostring (lua_State *L, int idx); |
148 | LUA_API size_t lua_strlen (lua_State *L, int idx); | 148 | LUA_API size_t lua_objsize (lua_State *L, int idx); |
149 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx); | 149 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx); |
150 | LUA_API void *lua_touserdata (lua_State *L, int idx); | 150 | LUA_API void *lua_touserdata (lua_State *L, int idx); |
151 | LUA_API lua_State *lua_tothread (lua_State *L, int idx); | 151 | LUA_API lua_State *lua_tothread (lua_State *L, int idx); |
@@ -244,11 +244,6 @@ LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud); | |||
244 | ** =============================================================== | 244 | ** =============================================================== |
245 | */ | 245 | */ |
246 | 246 | ||
247 | #define lua_boxpointer(L,u) \ | ||
248 | (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u)) | ||
249 | |||
250 | #define lua_unboxpointer(L,i) (*(void **)(lua_touserdata(L, i))) | ||
251 | |||
252 | #define lua_pop(L,n) lua_settop(L, -(n)-1) | 247 | #define lua_pop(L,n) lua_settop(L, -(n)-1) |
253 | 248 | ||
254 | #define lua_newtable(L) lua_createtable(L, 0, 0) | 249 | #define lua_newtable(L) lua_createtable(L, 0, 0) |
@@ -257,6 +252,8 @@ LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud); | |||
257 | 252 | ||
258 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) | 253 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) |
259 | 254 | ||
255 | #define lua_strlen(L,i) lua_objsize(L,i) | ||
256 | |||
260 | #define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION) | 257 | #define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION) |
261 | #define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE) | 258 | #define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE) |
262 | #define lua_islightuserdata(L,n) (lua_type(L,n) == LUA_TLIGHTUSERDATA) | 259 | #define lua_islightuserdata(L,n) (lua_type(L,n) == LUA_TLIGHTUSERDATA) |