diff options
-rw-r--r-- | lapi.c | 11 | ||||
-rw-r--r-- | lstring.c | 16 | ||||
-rw-r--r-- | lstring.h | 4 | ||||
-rw-r--r-- | ltests.c | 21 | ||||
-rw-r--r-- | lua.h | 7 |
5 files changed, 34 insertions, 25 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.125 2001/02/02 15:13:05 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.126 2001/02/07 18:13:49 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 | */ |
@@ -335,14 +335,13 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) { | |||
335 | } | 335 | } |
336 | 336 | ||
337 | 337 | ||
338 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) { | 338 | LUA_API int lua_pushuserdata (lua_State *L, void *u) { |
339 | int isnew; | ||
339 | LUA_LOCK(L); | 340 | LUA_LOCK(L); |
340 | /* ORDER LUA_T */ | 341 | isnew = luaS_createudata(L, u, L->top); |
341 | if (!(tag == LUA_ANYTAG || tag == LUA_TUSERDATA || validtag(G(L), tag))) | ||
342 | luaO_verror(L, "invalid tag for a userdata (%d)", tag); | ||
343 | setuvalue(L->top, luaS_createudata(L, u, tag)); | ||
344 | api_incr_top(L); | 342 | api_incr_top(L); |
345 | LUA_UNLOCK(L); | 343 | LUA_UNLOCK(L); |
344 | return isnew; | ||
346 | } | 345 | } |
347 | 346 | ||
348 | 347 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.54 2001/02/01 13:56:49 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.55 2001/02/01 17:40:48 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -102,17 +102,17 @@ TString *luaS_newudata (lua_State *L, size_t s, void *udata) { | |||
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | TString *luaS_createudata (lua_State *L, void *udata, int tag) { | 105 | int luaS_createudata (lua_State *L, void *udata, TObject *o) { |
106 | int h1 = lmod(IntPoint(udata), G(L)->udt.size); | 106 | int h1 = lmod(IntPoint(udata), G(L)->udt.size); |
107 | TString *ts; | 107 | TString *ts; |
108 | for (ts = G(L)->udt.hash[h1]; ts; ts = ts->nexthash) { | 108 | for (ts = G(L)->udt.hash[h1]; ts; ts = ts->nexthash) { |
109 | if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG)) | 109 | if (udata == ts->u.d.value) { |
110 | return ts; | 110 | setuvalue(o, ts); |
111 | return 0; | ||
112 | } | ||
111 | } | 113 | } |
112 | /* not found */ | 114 | /* not found */ |
113 | ts = luaS_newudata(L, 0, udata); | 115 | setuvalue(o, luaS_newudata(L, 0, udata)); |
114 | if (tag != LUA_ANYTAG) | 116 | return 1; |
115 | ts->u.d.tag = tag; | ||
116 | return ts; | ||
117 | } | 117 | } |
118 | 118 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.h,v 1.26 2000/12/28 12:55:41 roberto Exp roberto $ | 2 | ** $Id: lstring.h,v 1.27 2001/01/10 17:41:50 roberto Exp roberto $ |
3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keep all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -42,7 +42,7 @@ union L_UTString { | |||
42 | void luaS_init (lua_State *L); | 42 | void luaS_init (lua_State *L); |
43 | void luaS_resize (lua_State *L, stringtable *tb, int newsize); | 43 | void luaS_resize (lua_State *L, stringtable *tb, int newsize); |
44 | TString *luaS_newudata (lua_State *L, size_t s, void *udata); | 44 | TString *luaS_newudata (lua_State *L, size_t s, void *udata); |
45 | TString *luaS_createudata (lua_State *L, void *udata, int tag); | 45 | int luaS_createudata (lua_State *L, void *udata, TObject *o); |
46 | void luaS_freeall (lua_State *L); | 46 | void luaS_freeall (lua_State *L); |
47 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l); | 47 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l); |
48 | 48 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.63 2001/02/06 16:01:29 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.64 2001/02/06 18:18:58 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 | */ |
@@ -348,11 +348,17 @@ static int unref (lua_State *L) { | |||
348 | } | 348 | } |
349 | 349 | ||
350 | static int newuserdata (lua_State *L) { | 350 | static int newuserdata (lua_State *L) { |
351 | if (lua_isnumber(L, 2)) | 351 | if (lua_isnumber(L, 2)) { |
352 | lua_pushusertag(L, (void *)luaL_check_int(L, 1), luaL_check_int(L, 2)); | 352 | int tag = luaL_check_int(L, 2); |
353 | else | 353 | int res = lua_pushuserdata(L, (void *)luaL_check_int(L, 1)); |
354 | if (tag) lua_settag(L, tag); | ||
355 | lua_pushnumber(L, res); | ||
356 | return 2; | ||
357 | } | ||
358 | else { | ||
354 | lua_newuserdata(L, luaL_check_int(L, 1)); | 359 | lua_newuserdata(L, luaL_check_int(L, 1)); |
355 | return 1; | 360 | return 1; |
361 | } | ||
356 | } | 362 | } |
357 | 363 | ||
358 | static int udataval (lua_State *L) { | 364 | static int udataval (lua_State *L) { |
@@ -361,6 +367,10 @@ static int udataval (lua_State *L) { | |||
361 | return 1; | 367 | return 1; |
362 | } | 368 | } |
363 | 369 | ||
370 | static int newtag (lua_State *L) { | ||
371 | lua_pushnumber(L, lua_newtype(L, lua_tostring(L, 1), lua_tonumber(L, 2))); | ||
372 | return 1; | ||
373 | } | ||
364 | 374 | ||
365 | static int doonnewstack (lua_State *L) { | 375 | static int doonnewstack (lua_State *L) { |
366 | lua_State *L1 = lua_open(L, luaL_check_int(L, 1)); | 376 | lua_State *L1 = lua_open(L, luaL_check_int(L, 1)); |
@@ -631,6 +641,7 @@ static const struct luaL_reg tests_funcs[] = { | |||
631 | {"unref", unref}, | 641 | {"unref", unref}, |
632 | {"newuserdata", newuserdata}, | 642 | {"newuserdata", newuserdata}, |
633 | {"udataval", udataval}, | 643 | {"udataval", udataval}, |
644 | {"newtag", newtag}, | ||
634 | {"doonnewstack", doonnewstack}, | 645 | {"doonnewstack", doonnewstack}, |
635 | {"newstate", newstate}, | 646 | {"newstate", newstate}, |
636 | {"closestate", closestate}, | 647 | {"closestate", closestate}, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.84 2001/01/25 16:45:36 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.85 2001/01/26 11:45:51 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 |
@@ -32,7 +32,6 @@ | |||
32 | #define LUA_REFREGISTRY 0 | 32 | #define LUA_REFREGISTRY 0 |
33 | 33 | ||
34 | /* pre-defined tags */ | 34 | /* pre-defined tags */ |
35 | #define LUA_ANYTAG (-1) | ||
36 | #define LUA_NOTAG (-2) | 35 | #define LUA_NOTAG (-2) |
37 | 36 | ||
38 | 37 | ||
@@ -137,7 +136,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n); | |||
137 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len); | 136 | LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len); |
138 | LUA_API void lua_pushstring (lua_State *L, const char *s); | 137 | LUA_API void lua_pushstring (lua_State *L, const char *s); |
139 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); | 138 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); |
140 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag); | 139 | LUA_API int lua_pushuserdata (lua_State *L, void *u); |
141 | 140 | ||
142 | 141 | ||
143 | /* | 142 | /* |
@@ -210,7 +209,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size); | |||
210 | #define lua_pop(L,n) lua_settop(L, -(n)-1) | 209 | #define lua_pop(L,n) lua_settop(L, -(n)-1) |
211 | 210 | ||
212 | #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n)) | 211 | #define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n)) |
213 | #define lua_pushuserdata(L,u) lua_pushusertag(L, u, 0) | 212 | #define lua_pushusertag(L,u,t) (lua_pushuserdata(L, u), lua_settag(L, t)) |
214 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) | 213 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) |
215 | #define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t)) | 214 | #define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t)) |
216 | 215 | ||