diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-04-05 15:54:31 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-04-05 15:54:31 -0300 |
| commit | 237969724f54eeefee057ae382237c8db54af44e (patch) | |
| tree | fc4abd54f7cac0749023f1c021e7d86e3ee4f273 | |
| parent | f438d00ef31e3aea54023602f529b68834ffb80a (diff) | |
| download | lua-237969724f54eeefee057ae382237c8db54af44e.tar.gz lua-237969724f54eeefee057ae382237c8db54af44e.tar.bz2 lua-237969724f54eeefee057ae382237c8db54af44e.zip | |
support for `light' userdata + simpler support for `boxed' udata
| -rw-r--r-- | lapi.c | 44 | ||||
| -rw-r--r-- | lbaselib.c | 11 | ||||
| -rw-r--r-- | lgc.c | 5 | ||||
| -rw-r--r-- | liolib.c | 8 | ||||
| -rw-r--r-- | lobject.c | 6 | ||||
| -rw-r--r-- | lobject.h | 17 | ||||
| -rw-r--r-- | lstring.c | 3 | ||||
| -rw-r--r-- | ltable.c | 6 | ||||
| -rw-r--r-- | ltests.c | 10 | ||||
| -rw-r--r-- | ltm.c | 5 | ||||
| -rw-r--r-- | lua.c | 4 | ||||
| -rw-r--r-- | lua.h | 16 |
12 files changed, 71 insertions, 64 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.181 2002/03/27 12:49:53 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.182 2002/04/02 20:43:18 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 | */ |
| @@ -278,7 +278,12 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { | |||
| 278 | 278 | ||
| 279 | LUA_API void *lua_touserdata (lua_State *L, int index) { | 279 | LUA_API void *lua_touserdata (lua_State *L, int index) { |
| 280 | StkId o = luaA_indexAcceptable(L, index); | 280 | StkId o = luaA_indexAcceptable(L, index); |
| 281 | return (o == NULL || ttype(o) != LUA_TUSERDATA) ? NULL : uvalue(o)->uv.value; | 281 | if (o == NULL) return NULL; |
| 282 | switch (ttype(o)) { | ||
| 283 | case LUA_TUSERDATA: return (uvalue(o) + 1); | ||
| 284 | case LUA_TUDATAVAL: return pvalue(o); | ||
| 285 | default: return NULL; | ||
| 286 | } | ||
| 282 | } | 287 | } |
| 283 | 288 | ||
| 284 | 289 | ||
| @@ -356,6 +361,14 @@ LUA_API void lua_pushboolean (lua_State *L, int b) { | |||
| 356 | } | 361 | } |
| 357 | 362 | ||
| 358 | 363 | ||
| 364 | LUA_API void lua_pushudataval (lua_State *L, void *p) { | ||
| 365 | lua_lock(L); | ||
| 366 | setpvalue(L->top, p); | ||
| 367 | api_incr_top(L); | ||
| 368 | lua_unlock(L); | ||
| 369 | } | ||
| 370 | |||
| 371 | |||
| 359 | 372 | ||
| 360 | /* | 373 | /* |
| 361 | ** get functions (Lua -> stack) | 374 | ** get functions (Lua -> stack) |
| @@ -472,7 +485,7 @@ LUA_API void lua_setmetatable (lua_State *L, int objindex) { | |||
| 472 | StkId obj, mt; | 485 | StkId obj, mt; |
| 473 | lua_lock(L); | 486 | lua_lock(L); |
| 474 | api_checknelems(L, 1); | 487 | api_checknelems(L, 1); |
| 475 | obj = luaA_indexAcceptable(L, objindex); | 488 | obj = luaA_index(L, objindex); |
| 476 | mt = --L->top; | 489 | mt = --L->top; |
| 477 | if (ttype(mt) == LUA_TNIL) | 490 | if (ttype(mt) == LUA_TNIL) |
| 478 | mt = defaultmeta(L); | 491 | mt = defaultmeta(L); |
| @@ -649,31 +662,14 @@ LUA_API void lua_concat (lua_State *L, int n) { | |||
| 649 | } | 662 | } |
| 650 | 663 | ||
| 651 | 664 | ||
| 652 | static Udata *pushnewudata (lua_State *L, size_t size) { | ||
| 653 | Udata *u = luaS_newudata(L, size); | ||
| 654 | setuvalue(L->top, u); | ||
| 655 | api_incr_top(L); | ||
| 656 | return uvalue(L->top-1); | ||
| 657 | } | ||
| 658 | |||
| 659 | |||
| 660 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | 665 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { |
| 661 | Udata *u; | 666 | Udata *u; |
| 662 | void *p; | ||
| 663 | lua_lock(L); | 667 | lua_lock(L); |
| 664 | u = pushnewudata(L, size); | 668 | u = luaS_newudata(L, size); |
| 665 | p = u->uv.value; | 669 | setuvalue(L->top, u); |
| 666 | lua_unlock(L); | 670 | api_incr_top(L); |
| 667 | return p; | ||
| 668 | } | ||
| 669 | |||
| 670 | |||
| 671 | LUA_API void lua_newuserdatabox (lua_State *L, void *p) { | ||
| 672 | Udata *u; | ||
| 673 | lua_lock(L); | ||
| 674 | u = pushnewudata(L, 0); | ||
| 675 | u->uv.value = p; | ||
| 676 | lua_unlock(L); | 671 | lua_unlock(L); |
| 672 | return u + 1; | ||
| 677 | } | 673 | } |
| 678 | 674 | ||
| 679 | 675 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.62 2002/03/27 15:30:41 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.63 2002/04/02 20:42:20 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -206,7 +206,7 @@ static int passresults (lua_State *L, int status, int oldtop) { | |||
| 206 | if (nresults > 0) | 206 | if (nresults > 0) |
| 207 | return nresults; /* results are already on the stack */ | 207 | return nresults; /* results are already on the stack */ |
| 208 | else { | 208 | else { |
| 209 | lua_newuserdatabox(L, NULL); /* at least one result to signal no errors */ | 209 | lua_pushboolean(L, 1); /* at least one result to signal no errors */ |
| 210 | return 1; | 210 | return 1; |
| 211 | } | 211 | } |
| 212 | } | 212 | } |
| @@ -383,6 +383,7 @@ static int luaB_tostring (lua_State *L) { | |||
| 383 | sprintf(buff, "function: %p", lua_topointer(L, 1)); | 383 | sprintf(buff, "function: %p", lua_topointer(L, 1)); |
| 384 | break; | 384 | break; |
| 385 | case LUA_TUSERDATA: | 385 | case LUA_TUSERDATA: |
| 386 | case LUA_TUDATAVAL: | ||
| 386 | sprintf(buff, "userdata: %p", lua_touserdata(L, 1)); | 387 | sprintf(buff, "userdata: %p", lua_touserdata(L, 1)); |
| 387 | break; | 388 | break; |
| 388 | case LUA_TNIL: | 389 | case LUA_TNIL: |
| @@ -439,7 +440,7 @@ static void base_open (lua_State *L) { | |||
| 439 | 440 | ||
| 440 | 441 | ||
| 441 | static int luaB_resume (lua_State *L) { | 442 | static int luaB_resume (lua_State *L) { |
| 442 | lua_State *co = (lua_State *)lua_touserdata(L, lua_upvalueindex(1)); | 443 | lua_State *co = (lua_State *)lua_getfrombox(L, lua_upvalueindex(1)); |
| 443 | if (lua_resume(L, co) != 0) | 444 | if (lua_resume(L, co) != 0) |
| 444 | lua_error(L, "error running co-routine"); | 445 | lua_error(L, "error running co-routine"); |
| 445 | return lua_gettop(L); | 446 | return lua_gettop(L); |
| @@ -448,7 +449,7 @@ static int luaB_resume (lua_State *L) { | |||
| 448 | 449 | ||
| 449 | 450 | ||
| 450 | static int gc_coroutine (lua_State *L) { | 451 | static int gc_coroutine (lua_State *L) { |
| 451 | lua_State *co = (lua_State *)lua_touserdata(L, 1); | 452 | lua_State *co = (lua_State *)lua_getfrombox(L, 1); |
| 452 | lua_closethread(L, co); | 453 | lua_closethread(L, co); |
| 453 | return 0; | 454 | return 0; |
| 454 | } | 455 | } |
| @@ -471,7 +472,7 @@ static int luaB_coroutine (lua_State *L) { | |||
| 471 | lua_unref(L, ref); | 472 | lua_unref(L, ref); |
| 472 | } | 473 | } |
| 473 | lua_cobegin(NL, n-1); | 474 | lua_cobegin(NL, n-1); |
| 474 | lua_newuserdatabox(L, NL); | 475 | lua_newpointerbox(L, NL); |
| 475 | lua_pushliteral(L, "Coroutine"); | 476 | lua_pushliteral(L, "Coroutine"); |
| 476 | lua_rawget(L, LUA_REGISTRYINDEX); | 477 | lua_rawget(L, LUA_REGISTRYINDEX); |
| 477 | lua_setmetatable(L, -2); | 478 | lua_setmetatable(L, -2); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.132 2002/03/20 18:54:29 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.133 2002/03/26 18:55:50 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -46,7 +46,8 @@ typedef struct GCState { | |||
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | #define ismarkable(o) (!((1 << ttype(o)) & \ | 48 | #define ismarkable(o) (!((1 << ttype(o)) & \ |
| 49 | ((1 << LUA_TNIL) | (1 << LUA_TNUMBER) | (1 << LUA_TBOOLEAN)))) | 49 | ((1 << LUA_TNIL) | (1 << LUA_TNUMBER) | \ |
| 50 | (1 << LUA_TBOOLEAN) | (1 << LUA_TUDATAVAL)))) | ||
| 50 | 51 | ||
| 51 | static void reallymarkobject (GCState *st, TObject *o); | 52 | static void reallymarkobject (GCState *st, TObject *o); |
| 52 | 53 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.133 2002/03/27 15:30:41 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.1 2002/04/04 20:24:56 roberto Exp roberto $ |
| 3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -54,11 +54,11 @@ static int pushresult (lua_State *L, int i) { | |||
| 54 | 54 | ||
| 55 | 55 | ||
| 56 | static FILE *tofile (lua_State *L, int findex) { | 56 | static FILE *tofile (lua_State *L, int findex) { |
| 57 | FILE *f = (FILE *)lua_touserdata(L, findex); | 57 | FILE **f = (FILE **)lua_touserdata(L, findex); |
| 58 | if (f && lua_getmetatable(L, findex) && | 58 | if (f && lua_getmetatable(L, findex) && |
| 59 | lua_equal(L, -1, lua_upvalueindex(1))) { | 59 | lua_equal(L, -1, lua_upvalueindex(1))) { |
| 60 | lua_pop(L, 1); | 60 | lua_pop(L, 1); |
| 61 | return f; | 61 | return *f; |
| 62 | } | 62 | } |
| 63 | luaL_argerror(L, findex, "bad file"); | 63 | luaL_argerror(L, findex, "bad file"); |
| 64 | return NULL; /* to avoid warnings */ | 64 | return NULL; /* to avoid warnings */ |
| @@ -66,7 +66,7 @@ static FILE *tofile (lua_State *L, int findex) { | |||
| 66 | 66 | ||
| 67 | 67 | ||
| 68 | static void newfile (lua_State *L, FILE *f) { | 68 | static void newfile (lua_State *L, FILE *f) { |
| 69 | lua_newuserdatabox(L, f); | 69 | lua_newpointerbox(L, f); |
| 70 | lua_pushliteral(L, FILEHANDLE); | 70 | lua_pushliteral(L, FILEHANDLE); |
| 71 | lua_rawget(L, LUA_REGISTRYINDEX); | 71 | lua_rawget(L, LUA_REGISTRYINDEX); |
| 72 | lua_setmetatable(L, -2); | 72 | lua_setmetatable(L, -2); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.1 2001/11/29 22:14:34 rieru Exp rieru $ | 2 | ** $Id: lobject.c,v 1.75 2002/02/07 17:25:12 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -59,7 +59,9 @@ int luaO_equalObj (const TObject *t1, const TObject *t2) { | |||
| 59 | return 1; | 59 | return 1; |
| 60 | case LUA_TBOOLEAN: | 60 | case LUA_TBOOLEAN: |
| 61 | return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ | 61 | return bvalue(t1) == bvalue(t2); /* true must be 1 !! */ |
| 62 | default: /* all other types are equal if pointers are equal */ | 62 | case LUA_TUDATAVAL: |
| 63 | return pvalue(t1) == pvalue(t2); | ||
| 64 | default: /* other types are equal if struct pointers are equal */ | ||
| 63 | return tsvalue(t1) == tsvalue(t2); | 65 | return tsvalue(t1) == tsvalue(t2); |
| 64 | } | 66 | } |
| 65 | } | 67 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 1.127 2002/03/18 18:16:16 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.128 2002/03/25 17:47:14 roberto Exp roberto $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -13,15 +13,15 @@ | |||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | /* tags for values visible from Lua */ | 15 | /* tags for values visible from Lua */ |
| 16 | #define NUM_TAGS 6 | 16 | #define NUM_TAGS LUA_TFUNCTION |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | typedef union { | 19 | typedef union { |
| 20 | void *p; | ||
| 20 | union TString *ts; | 21 | union TString *ts; |
| 21 | union Udata *u; | 22 | union Udata *u; |
| 22 | union Closure *cl; | 23 | union Closure *cl; |
| 23 | struct Table *h; | 24 | struct Table *h; |
| 24 | struct lua_TObject *v; | ||
| 25 | lua_Number n; | 25 | lua_Number n; |
| 26 | int b; | 26 | int b; |
| 27 | } Value; | 27 | } Value; |
| @@ -35,12 +35,12 @@ typedef struct lua_TObject { | |||
| 35 | 35 | ||
| 36 | /* Macros to access values */ | 36 | /* Macros to access values */ |
| 37 | #define ttype(o) ((o)->tt) | 37 | #define ttype(o) ((o)->tt) |
| 38 | #define pvalue(o) ((o)->value.p) | ||
| 38 | #define nvalue(o) ((o)->value.n) | 39 | #define nvalue(o) ((o)->value.n) |
| 39 | #define tsvalue(o) ((o)->value.ts) | 40 | #define tsvalue(o) ((o)->value.ts) |
| 40 | #define uvalue(o) ((o)->value.u) | 41 | #define uvalue(o) ((o)->value.u) |
| 41 | #define clvalue(o) ((o)->value.cl) | 42 | #define clvalue(o) ((o)->value.cl) |
| 42 | #define hvalue(o) ((o)->value.h) | 43 | #define hvalue(o) ((o)->value.h) |
| 43 | #define vvalue(o) ((o)->value.v) | ||
| 44 | #define bvalue(o) ((o)->value.b) | 44 | #define bvalue(o) ((o)->value.b) |
| 45 | 45 | ||
| 46 | #define l_isfalse(o) (ttype(o) == LUA_TNIL || \ | 46 | #define l_isfalse(o) (ttype(o) == LUA_TNIL || \ |
| @@ -52,6 +52,9 @@ typedef struct lua_TObject { | |||
| 52 | 52 | ||
| 53 | #define chgnvalue(obj,x) ((obj)->value.n=(x)) | 53 | #define chgnvalue(obj,x) ((obj)->value.n=(x)) |
| 54 | 54 | ||
| 55 | #define setpvalue(obj,x) \ | ||
| 56 | { TObject *i_o=(obj); i_o->tt=LUA_TUDATAVAL; i_o->value.p=(x); } | ||
| 57 | |||
| 55 | #define setbvalue(obj,x) \ | 58 | #define setbvalue(obj,x) \ |
| 56 | { TObject *i_o=(obj); i_o->tt=LUA_TBOOLEAN; i_o->value.b=(x); } | 59 | { TObject *i_o=(obj); i_o->tt=LUA_TBOOLEAN; i_o->value.b=(x); } |
| 57 | 60 | ||
| @@ -69,9 +72,6 @@ typedef struct lua_TObject { | |||
| 69 | 72 | ||
| 70 | #define setnilvalue(obj) ((obj)->tt=LUA_TNIL) | 73 | #define setnilvalue(obj) ((obj)->tt=LUA_TNIL) |
| 71 | 74 | ||
| 72 | #define setupvalue(obj,x,t) \ | ||
| 73 | { TObject *i_o=(obj); i_o->tt=(t); i_o->value.v=(x); } | ||
| 74 | |||
| 75 | #define setobj(obj1,obj2) \ | 75 | #define setobj(obj1,obj2) \ |
| 76 | { TObject *o1=(obj1); const TObject *o2=(obj2); \ | 76 | { TObject *o1=(obj1); const TObject *o2=(obj2); \ |
| 77 | o1->tt=o2->tt; o1->value = o2->value; } | 77 | o1->tt=o2->tt; o1->value = o2->value; } |
| @@ -106,9 +106,8 @@ typedef union Udata { | |||
| 106 | union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | 106 | union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ |
| 107 | struct { | 107 | struct { |
| 108 | struct Table *metatable; | 108 | struct Table *metatable; |
| 109 | void *value; | ||
| 110 | union Udata *next; /* chain for list of all udata */ | 109 | union Udata *next; /* chain for list of all udata */ |
| 111 | size_t len; /* least bit reserved for gc mark */ | 110 | size_t len; /* least 2 bits reserved for gc mark */ |
| 112 | } uv; | 111 | } uv; |
| 113 | } Udata; | 112 | } Udata; |
| 114 | 113 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.72 2002/02/08 22:41:09 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.73 2002/03/20 18:37:13 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 | */ |
| @@ -89,7 +89,6 @@ Udata *luaS_newudata (lua_State *L, size_t s) { | |||
| 89 | u = cast(Udata *, luaM_malloc(L, sizeudata(s))); | 89 | u = cast(Udata *, luaM_malloc(L, sizeudata(s))); |
| 90 | u->uv.len = s; | 90 | u->uv.len = s; |
| 91 | u->uv.metatable = hvalue(defaultmeta(L)); | 91 | u->uv.metatable = hvalue(defaultmeta(L)); |
| 92 | u->uv.value = u + 1; | ||
| 93 | /* chain it on udata list */ | 92 | /* chain it on udata list */ |
| 94 | u->uv.next = G(L)->rootudata; | 93 | u->uv.next = G(L)->rootudata; |
| 95 | G(L)->rootudata = u; | 94 | G(L)->rootudata = u; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 1.101 2002/02/14 21:41:08 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.102 2002/03/18 18:18:35 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -73,7 +73,9 @@ Node *luaH_mainposition (const Table *t, const TObject *key) { | |||
| 73 | return hashstr(t, tsvalue(key)); | 73 | return hashstr(t, tsvalue(key)); |
| 74 | case LUA_TBOOLEAN: | 74 | case LUA_TBOOLEAN: |
| 75 | return hashboolean(t, bvalue(key)); | 75 | return hashboolean(t, bvalue(key)); |
| 76 | default: /* all other types are hashed as (void *) */ | 76 | case LUA_TUDATAVAL: |
| 77 | return hashpointer(t, pvalue(key)); | ||
| 78 | default: /* other types are hashed as (struct *) */ | ||
| 77 | return hashpointer(t, tsvalue(key)); | 79 | return hashpointer(t, tsvalue(key)); |
| 78 | } | 80 | } |
| 79 | } | 81 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.114 2002/03/25 17:47:14 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.115 2002/04/02 20:43:08 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 | */ |
| @@ -368,14 +368,14 @@ static int newuserdata (lua_State *L) { | |||
| 368 | return 1; | 368 | return 1; |
| 369 | } | 369 | } |
| 370 | 370 | ||
| 371 | static int newuserdatabox (lua_State *L) { | 371 | |
| 372 | lua_newuserdatabox(L, cast(void *, luaL_check_int(L, 1))); | 372 | static int pushuserdata (lua_State *L) { |
| 373 | lua_pushudataval(L, cast(void *, luaL_check_int(L, 1))); | ||
| 373 | return 1; | 374 | return 1; |
| 374 | } | 375 | } |
| 375 | 376 | ||
| 376 | 377 | ||
| 377 | static int udataval (lua_State *L) { | 378 | static int udataval (lua_State *L) { |
| 378 | luaL_check_type(L, 1, LUA_TUSERDATA); | ||
| 379 | lua_pushnumber(L, cast(int, lua_touserdata(L, 1))); | 379 | lua_pushnumber(L, cast(int, lua_touserdata(L, 1))); |
| 380 | return 1; | 380 | return 1; |
| 381 | } | 381 | } |
| @@ -662,7 +662,7 @@ static const struct luaL_reg tests_funcs[] = { | |||
| 662 | {"s2d", s2d}, | 662 | {"s2d", s2d}, |
| 663 | {"metatable", metatable}, | 663 | {"metatable", metatable}, |
| 664 | {"newuserdata", newuserdata}, | 664 | {"newuserdata", newuserdata}, |
| 665 | {"newuserdatabox", newuserdatabox}, | 665 | {"pushuserdata", pushuserdata}, |
| 666 | {"udataval", udataval}, | 666 | {"udataval", udataval}, |
| 667 | {"doonnewstack", doonnewstack}, | 667 | {"doonnewstack", doonnewstack}, |
| 668 | {"newstate", newstate}, | 668 | {"newstate", newstate}, |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 1.87 2002/02/14 21:40:29 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.88 2002/03/18 20:24:14 roberto Exp roberto $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -19,7 +19,8 @@ | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | const char *const luaT_typenames[] = { | 21 | const char *const luaT_typenames[] = { |
| 22 | "nil", "number", "string", "boolean", "table", "userdata", "function" | 22 | "nil", "number", "string", "boolean", "table", |
| 23 | "userdata", "userdata", "function" | ||
| 23 | }; | 24 | }; |
| 24 | 25 | ||
| 25 | 26 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.79 2002/03/27 18:00:13 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.80 2002/04/01 14:42:33 roberto Exp roberto $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -334,7 +334,7 @@ static int handle_argv (char *argv[], int *toclose) { | |||
| 334 | 334 | ||
| 335 | 335 | ||
| 336 | static void register_getargs (char *argv[]) { | 336 | static void register_getargs (char *argv[]) { |
| 337 | lua_newuserdatabox(L, argv); | 337 | lua_pushudataval(L, argv); |
| 338 | lua_pushcclosure(L, l_getargs, 1); | 338 | lua_pushcclosure(L, l_getargs, 1); |
| 339 | lua_setglobal(L, "getargs"); | 339 | lua_setglobal(L, "getargs"); |
| 340 | } | 340 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.124 2002/03/27 12:49:53 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.125 2002/03/27 15:30:41 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: info@lua.org | 5 | ** e-mail: info@lua.org |
| @@ -17,8 +17,8 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | #define LUA_VERSION "Lua 4.1 (beta)" | 20 | #define LUA_VERSION "Lua 5.0 (alpha)" |
| 21 | #define LUA_COPYRIGHT "Copyright (C) 1994-2001 TeCGraf, PUC-Rio" | 21 | #define LUA_COPYRIGHT "Copyright (C) 1994-2002 TeCGraf, PUC-Rio" |
| 22 | #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" | 22 | #define LUA_AUTHORS "W. Celes, R. Ierusalimschy & L. H. de Figueiredo" |
| 23 | 23 | ||
| 24 | 24 | ||
| @@ -63,7 +63,8 @@ typedef int (*lua_CFunction) (lua_State *L); | |||
| 63 | #define LUA_TBOOLEAN 3 | 63 | #define LUA_TBOOLEAN 3 |
| 64 | #define LUA_TTABLE 4 | 64 | #define LUA_TTABLE 4 |
| 65 | #define LUA_TUSERDATA 5 | 65 | #define LUA_TUSERDATA 5 |
| 66 | #define LUA_TFUNCTION 6 | 66 | #define LUA_TUDATAVAL 6 |
| 67 | #define LUA_TFUNCTION 7 | ||
| 67 | 68 | ||
| 68 | 69 | ||
| 69 | /* minimum Lua stack available to a C function */ | 70 | /* minimum Lua stack available to a C function */ |
| @@ -143,6 +144,7 @@ LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len); | |||
| 143 | LUA_API void lua_pushstring (lua_State *L, const char *s); | 144 | LUA_API void lua_pushstring (lua_State *L, const char *s); |
| 144 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); | 145 | LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n); |
| 145 | LUA_API void lua_pushboolean (lua_State *L, int b); | 146 | LUA_API void lua_pushboolean (lua_State *L, int b); |
| 147 | LUA_API void lua_pushudataval (lua_State *L, void *p); | ||
| 146 | 148 | ||
| 147 | 149 | ||
| 148 | /* | 150 | /* |
| @@ -204,7 +206,6 @@ LUA_API int lua_getn (lua_State *L, int index); | |||
| 204 | LUA_API void lua_concat (lua_State *L, int n); | 206 | LUA_API void lua_concat (lua_State *L, int n); |
| 205 | 207 | ||
| 206 | LUA_API void *lua_newuserdata (lua_State *L, size_t size); | 208 | LUA_API void *lua_newuserdata (lua_State *L, size_t size); |
| 207 | LUA_API void lua_newuserdatabox (lua_State *L, void *u); | ||
| 208 | 209 | ||
| 209 | 210 | ||
| 210 | 211 | ||
| @@ -214,6 +215,11 @@ LUA_API void lua_newuserdatabox (lua_State *L, void *u); | |||
| 214 | ** =============================================================== | 215 | ** =============================================================== |
| 215 | */ | 216 | */ |
| 216 | 217 | ||
| 218 | #define lua_newpointerbox(L,u) \ | ||
| 219 | (*(void **)(lua_newuserdata(L, sizeof(void *))) = (u)) | ||
| 220 | |||
| 221 | #define lua_getfrombox(L,i) (*(void **)(lua_touserdata(L, i))) | ||
| 222 | |||
| 217 | #define lua_pop(L,n) lua_settop(L, -(n)-1) | 223 | #define lua_pop(L,n) lua_settop(L, -(n)-1) |
| 218 | 224 | ||
| 219 | #define lua_register(L,n,f) \ | 225 | #define lua_register(L,n,f) \ |
