diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-26 10:47:05 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-26 10:47:05 -0200 |
commit | b892f0a8774f573d7ec9b02617428871b8d3a2b3 (patch) | |
tree | 4aab88443264d84d314ca663cf3c30b48c7e9107 | |
parent | aadc35449ec2752c298a7a8fa6359a3a12c538ee (diff) | |
download | lua-b892f0a8774f573d7ec9b02617428871b8d3a2b3.tar.gz lua-b892f0a8774f573d7ec9b02617428871b8d3a2b3.tar.bz2 lua-b892f0a8774f573d7ec9b02617428871b8d3a2b3.zip |
new API function `createuserdata'
-rw-r--r-- | lapi.c | 13 | ||||
-rw-r--r-- | lgc.c | 6 | ||||
-rw-r--r-- | liolib.c | 30 | ||||
-rw-r--r-- | llimits.h | 7 | ||||
-rw-r--r-- | lmathlib.c | 10 | ||||
-rw-r--r-- | lmem.c | 5 | ||||
-rw-r--r-- | lobject.h | 5 | ||||
-rw-r--r-- | lstate.c | 3 | ||||
-rw-r--r-- | lstring.c | 35 | ||||
-rw-r--r-- | lstring.h | 4 | ||||
-rw-r--r-- | ltable.c | 4 | ||||
-rw-r--r-- | ltests.c | 7 | ||||
-rw-r--r-- | lua.h | 4 | ||||
-rw-r--r-- | lvm.c | 16 |
14 files changed, 83 insertions, 66 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.107 2000/10/20 16:39:03 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.108 2000/10/24 19:19:15 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 | */ |
@@ -173,7 +173,7 @@ LUA_API const char *lua_tostring (lua_State *L, int index) { | |||
173 | LUA_API size_t lua_strlen (lua_State *L, int index) { | 173 | LUA_API size_t lua_strlen (lua_State *L, int index) { |
174 | StkId o = luaA_indexAcceptable(L, index); | 174 | StkId o = luaA_indexAcceptable(L, index); |
175 | if (o == NULL || tostring(L, o)) return 0; | 175 | if (o == NULL || tostring(L, o)) return 0; |
176 | else return tsvalue(o)->u.s.len; | 176 | else return tsvalue(o)->len; |
177 | } | 177 | } |
178 | 178 | ||
179 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { | 179 | LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index) { |
@@ -491,3 +491,12 @@ LUA_API void lua_concat (lua_State *L, int n) { | |||
491 | luaC_checkGC(L); | 491 | luaC_checkGC(L); |
492 | } | 492 | } |
493 | 493 | ||
494 | |||
495 | LUA_API void *lua_newuserdata (lua_State *L, size_t size) { | ||
496 | TString *ts = luaS_newudata(L, size, NULL); | ||
497 | tsvalue(L->top) = ts; | ||
498 | ttype(L->top) = LUA_TUSERDATA; | ||
499 | api_incr_top(L); | ||
500 | return ts->u.d.value; | ||
501 | } | ||
502 | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.70 2000/10/05 12:14:08 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.71 2000/10/05 13:00:17 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 | */ |
@@ -248,7 +248,7 @@ static void collectstrings (lua_State *L, int all) { | |||
248 | else { /* collect */ | 248 | else { /* collect */ |
249 | *p = next->nexthash; | 249 | *p = next->nexthash; |
250 | L->strt.nuse--; | 250 | L->strt.nuse--; |
251 | L->nblocks -= sizestring(next->u.s.len); | 251 | L->nblocks -= sizestring(next->len); |
252 | luaM_free(L, next); | 252 | luaM_free(L, next); |
253 | } | 253 | } |
254 | } | 254 | } |
@@ -273,7 +273,7 @@ static void collectudata (lua_State *L, int all) { | |||
273 | *p = next->nexthash; | 273 | *p = next->nexthash; |
274 | next->nexthash = L->TMtable[tag].collected; /* chain udata */ | 274 | next->nexthash = L->TMtable[tag].collected; /* chain udata */ |
275 | L->TMtable[tag].collected = next; | 275 | L->TMtable[tag].collected = next; |
276 | L->nblocks -= gcsizeudata; | 276 | L->nblocks -= sizestring(next->len); |
277 | L->udt.nuse--; | 277 | L->udt.nuse--; |
278 | } | 278 | } |
279 | } | 279 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 1.86 2000/10/02 20:10:55 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.87 2000/10/20 16:39:03 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 | */ |
@@ -159,18 +159,9 @@ static int io_close (lua_State *L) { | |||
159 | 159 | ||
160 | static int file_collect (lua_State *L) { | 160 | static int file_collect (lua_State *L) { |
161 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); | 161 | IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); |
162 | lua_pop(L, 1); /* remove upvalue */ | 162 | FILE *f = getnonullfile(L, ctrl, 1); |
163 | if (ctrl == (IOCtrl *)lua_touserdata(L, 1)) { | 163 | if (f != stdin && f != stdout && f != stderr) |
164 | /* collecting `ctrl' itself */ | 164 | CLOSEFILE(L, f); |
165 | lua_unref(L, ctrl->ref[INFILE]); | ||
166 | lua_unref(L, ctrl->ref[OUTFILE]); | ||
167 | free(ctrl); | ||
168 | } | ||
169 | else { /* collecting a file: Close it */ | ||
170 | FILE *f = getnonullfile(L, ctrl, 1); | ||
171 | if (f != stdin && f != stdout && f != stderr) | ||
172 | CLOSEFILE(L, f); | ||
173 | } | ||
174 | return 0; | 165 | return 0; |
175 | } | 166 | } |
176 | 167 | ||
@@ -690,14 +681,13 @@ static const struct luaL_reg iolibtag[] = { | |||
690 | 681 | ||
691 | 682 | ||
692 | static void openwithcontrol (lua_State *L) { | 683 | static void openwithcontrol (lua_State *L) { |
693 | IOCtrl *ctrl = (IOCtrl *)malloc(sizeof(IOCtrl)); | 684 | IOCtrl *ctrl = (IOCtrl *)lua_newuserdata(L, sizeof(IOCtrl)); |
694 | unsigned int i; | 685 | unsigned int i; |
695 | int ctrltag = lua_newtag(L); | ||
696 | ctrl->iotag = lua_newtag(L); | 686 | ctrl->iotag = lua_newtag(L); |
697 | ctrl->closedtag = lua_newtag(L); | 687 | ctrl->closedtag = lua_newtag(L); |
698 | for (i=0; i<sizeof(iolibtag)/sizeof(iolibtag[0]); i++) { | 688 | for (i=0; i<sizeof(iolibtag)/sizeof(iolibtag[0]); i++) { |
699 | /* put `ctrl' as upvalue for these functions */ | 689 | /* put `ctrl' as upvalue for these functions */ |
700 | lua_pushusertag(L, ctrl, ctrltag); | 690 | lua_pushvalue(L, -1); |
701 | lua_pushcclosure(L, iolibtag[i].func, 1); | 691 | lua_pushcclosure(L, iolibtag[i].func, 1); |
702 | lua_setglobal(L, iolibtag[i].name); | 692 | lua_setglobal(L, iolibtag[i].name); |
703 | } | 693 | } |
@@ -712,12 +702,10 @@ static void openwithcontrol (lua_State *L) { | |||
712 | setfilebyname(L, ctrl, stdin, "_STDIN"); | 702 | setfilebyname(L, ctrl, stdin, "_STDIN"); |
713 | setfilebyname(L, ctrl, stdout, "_STDOUT"); | 703 | setfilebyname(L, ctrl, stdout, "_STDOUT"); |
714 | setfilebyname(L, ctrl, stderr, "_STDERR"); | 704 | setfilebyname(L, ctrl, stderr, "_STDERR"); |
715 | /* delete `ctrl' when collected */ | ||
716 | lua_pushusertag(L, ctrl, ctrltag); | ||
717 | lua_pushcclosure(L, file_collect, 1); | ||
718 | lua_settagmethod(L, ctrltag, "gc"); | ||
719 | /* close files when collected */ | 705 | /* close files when collected */ |
720 | lua_copytagmethods(L, ctrl->iotag, ctrltag); | 706 | lua_pushcclosure(L, file_collect, 1); /* pops `ctrl' from stack */ |
707 | lua_settagmethod(L, ctrl->iotag, "gc"); | ||
708 | lua_pop(L, 1); /* remove tag method returned by previous call */ | ||
721 | } | 709 | } |
722 | 710 | ||
723 | 711 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llimits.h,v 1.17 2000/10/06 19:28:38 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.18 2000/10/09 13:47:32 roberto Exp roberto $ |
3 | ** Limits, basic types, and some other "installation-dependent" definitions | 3 | ** Limits, basic types, and some other "installation-dependent" definitions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -76,6 +76,11 @@ typedef unsigned long lint32; /* unsigned int with at least 32 bits */ | |||
76 | 76 | ||
77 | 77 | ||
78 | 78 | ||
79 | /* type to ensure maximum alignment */ | ||
80 | union L_Umaxalign { double d; char *s; long l; }; | ||
81 | |||
82 | |||
83 | |||
79 | /* | 84 | /* |
80 | ** type for virtual-machine instructions | 85 | ** type for virtual-machine instructions |
81 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) | 86 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmathlib.c,v 1.28 2000/08/31 20:23:40 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.29 2000/10/20 16:39:03 roberto Exp roberto $ |
3 | ** Standard mathematical library | 3 | ** Standard mathematical library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -230,10 +230,10 @@ static const struct luaL_reg mathlib[] = { | |||
230 | */ | 230 | */ |
231 | LUA_API void lua_mathlibopen (lua_State *L) { | 231 | LUA_API void lua_mathlibopen (lua_State *L) { |
232 | luaL_openl(L, mathlib); | 232 | luaL_openl(L, mathlib); |
233 | lua_pushnumber(L, 0); /* to get its tag */ | ||
234 | lua_pushcfunction(L, math_pow); | 233 | lua_pushcfunction(L, math_pow); |
235 | lua_settagmethod(L, lua_tag(L, -2), "pow"); | 234 | lua_settagmethod(L, LUA_TNUMBER, "pow"); |
236 | lua_pop(L, 1); /* remove number */ | 235 | lua_pop(L, 1); /* remove result from previous call */ |
237 | lua_pushnumber(L, PI); lua_setglobal(L, "PI"); | 236 | lua_pushnumber(L, PI); |
237 | lua_setglobal(L, "PI"); | ||
238 | } | 238 | } |
239 | 239 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lmem.c,v 1.36 2000/08/09 19:16:57 roberto Exp roberto $ | 2 | ** $Id: lmem.c,v 1.37 2000/10/11 16:47:50 roberto Exp roberto $ |
3 | ** Interface to Memory Manager | 3 | ** Interface to Memory Manager |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -35,8 +35,7 @@ | |||
35 | 35 | ||
36 | 36 | ||
37 | /* ensures maximum alignment for HEADER */ | 37 | /* ensures maximum alignment for HEADER */ |
38 | union L_U { double d; char *s; long l; }; | 38 | #define HEADER (sizeof(union L_Umaxalign)) |
39 | #define HEADER (sizeof(union L_U)) | ||
40 | 39 | ||
41 | #define MARKSIZE 16 | 40 | #define MARKSIZE 16 |
42 | #define MARK 0x55 /* 01010101 (a nice pattern) */ | 41 | #define MARK 0x55 /* 01010101 (a nice pattern) */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 1.78 2000/10/02 20:10:55 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 1.79 2000/10/05 12:14:08 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 | */ |
@@ -73,9 +73,9 @@ typedef struct lua_TObject { | |||
73 | */ | 73 | */ |
74 | typedef struct TString { | 74 | typedef struct TString { |
75 | union { | 75 | union { |
76 | union L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | ||
76 | struct { /* for strings */ | 77 | struct { /* for strings */ |
77 | unsigned long hash; | 78 | unsigned long hash; |
78 | size_t len; | ||
79 | int constindex; /* hint to reuse constants */ | 79 | int constindex; /* hint to reuse constants */ |
80 | } s; | 80 | } s; |
81 | struct { /* for userdata */ | 81 | struct { /* for userdata */ |
@@ -83,6 +83,7 @@ typedef struct TString { | |||
83 | void *value; | 83 | void *value; |
84 | } d; | 84 | } d; |
85 | } u; | 85 | } u; |
86 | size_t len; | ||
86 | struct TString *nexthash; /* chain for hash table */ | 87 | struct TString *nexthash; /* chain for hash table */ |
87 | unsigned char marked; | 88 | unsigned char marked; |
88 | char str[1]; /* variable length string!! must be the last field! */ | 89 | char str[1]; /* variable length string!! must be the last field! */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 1.45 2000/10/20 16:39:03 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 1.46 2000/10/24 19:12:06 roberto Exp roberto $ |
3 | ** Global State | 3 | ** Global State |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -98,6 +98,7 @@ LUA_API lua_State *lua_open (int stacksize) { | |||
98 | 98 | ||
99 | 99 | ||
100 | LUA_API void lua_close (lua_State *L) { | 100 | LUA_API void lua_close (lua_State *L) { |
101 | LUA_ASSERT(L != lua_state || lua_gettop(L) == 0, "garbage in C stack"); | ||
101 | luaC_collect(L, 1); /* collect all elements */ | 102 | luaC_collect(L, 1); /* collect all elements */ |
102 | LUA_ASSERT(L->rootproto == NULL, "list should be empty"); | 103 | LUA_ASSERT(L->rootproto == NULL, "list should be empty"); |
103 | LUA_ASSERT(L->rootcl == NULL, "list should be empty"); | 104 | LUA_ASSERT(L->rootcl == NULL, "list should be empty"); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 1.42 2000/08/09 19:16:57 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.43 2000/09/29 12:42: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 | */ |
@@ -81,17 +81,17 @@ static void newentry (lua_State *L, stringtable *tb, TString *ts, int h) { | |||
81 | 81 | ||
82 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | 82 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { |
83 | unsigned long h = hash_s(str, l); | 83 | unsigned long h = hash_s(str, l); |
84 | int h1 = h&(L->strt.size-1); | 84 | int h1 = h & (L->strt.size-1); |
85 | TString *ts; | 85 | TString *ts; |
86 | for (ts = L->strt.hash[h1]; ts; ts = ts->nexthash) { | 86 | for (ts = L->strt.hash[h1]; ts; ts = ts->nexthash) { |
87 | if (ts->u.s.len == l && (memcmp(str, ts->str, l) == 0)) | 87 | if (ts->len == l && (memcmp(str, ts->str, l) == 0)) |
88 | return ts; | 88 | return ts; |
89 | } | 89 | } |
90 | /* not found */ | 90 | /* not found */ |
91 | ts = (TString *)luaM_malloc(L, sizestring(l)); | 91 | ts = (TString *)luaM_malloc(L, sizestring(l)); |
92 | ts->marked = 0; | 92 | ts->marked = 0; |
93 | ts->nexthash = NULL; | 93 | ts->nexthash = NULL; |
94 | ts->u.s.len = l; | 94 | ts->len = l; |
95 | ts->u.s.hash = h; | 95 | ts->u.s.hash = h; |
96 | ts->u.s.constindex = 0; | 96 | ts->u.s.constindex = 0; |
97 | memcpy(ts->str, str, l); | 97 | memcpy(ts->str, str, l); |
@@ -102,22 +102,31 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
105 | TString *luaS_newudata (lua_State *L, size_t s, void *udata) { | ||
106 | TString *ts = (TString *)luaM_malloc(L, (lint32)sizeof(TString)+s); | ||
107 | ts->marked = 0; | ||
108 | ts->nexthash = NULL; | ||
109 | ts->len = s; | ||
110 | ts->u.d.tag = 0; | ||
111 | ts->u.d.value = (udata == NULL) ? ts+1 : udata; | ||
112 | L->nblocks += sizestring(s); | ||
113 | /* insert it on table */ | ||
114 | newentry(L, &L->udt, ts, IntPoint(ts->u.d.value) & (L->udt.size-1)); | ||
115 | return ts; | ||
116 | } | ||
117 | |||
118 | |||
105 | TString *luaS_createudata (lua_State *L, void *udata, int tag) { | 119 | TString *luaS_createudata (lua_State *L, void *udata, int tag) { |
106 | unsigned long h = IntPoint(udata); | 120 | int h1 = IntPoint(udata) & (L->udt.size-1); |
107 | int h1 = h&(L->udt.size-1); | ||
108 | TString *ts; | 121 | TString *ts; |
109 | for (ts = L->udt.hash[h1]; ts; ts = ts->nexthash) { | 122 | for (ts = L->udt.hash[h1]; ts; ts = ts->nexthash) { |
110 | if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG)) | 123 | if (udata == ts->u.d.value && (tag == ts->u.d.tag || tag == LUA_ANYTAG)) |
111 | return ts; | 124 | return ts; |
112 | } | 125 | } |
113 | /* not found */ | 126 | /* not found */ |
114 | ts = luaM_new(L, TString); | 127 | ts = luaS_newudata(L, 0, udata); |
115 | ts->marked = 0; | 128 | if (tag != LUA_ANYTAG) |
116 | ts->nexthash = NULL; | 129 | ts->u.d.tag = tag; |
117 | ts->u.d.value = udata; | ||
118 | ts->u.d.tag = (tag == LUA_ANYTAG) ? 0 : tag; | ||
119 | L->nblocks += gcsizeudata; | ||
120 | newentry(L, &L->udt, ts, h1); /* insert it on table */ | ||
121 | return ts; | 130 | return ts; |
122 | } | 131 | } |
123 | 132 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.h,v 1.21 2000/05/24 13:54:49 roberto Exp roberto $ | 2 | ** $Id: lstring.h,v 1.22 2000/09/29 12:42:13 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 | */ |
@@ -21,11 +21,11 @@ | |||
21 | 21 | ||
22 | 22 | ||
23 | #define sizestring(l) (sizeof(TString)+(lint32)(l)*sizeof(char)) | 23 | #define sizestring(l) (sizeof(TString)+(lint32)(l)*sizeof(char)) |
24 | #define gcsizeudata (sizeof(TString)) | ||
25 | 24 | ||
26 | 25 | ||
27 | void luaS_init (lua_State *L); | 26 | void luaS_init (lua_State *L); |
28 | void luaS_resize (lua_State *L, stringtable *tb, int newsize); | 27 | void luaS_resize (lua_State *L, stringtable *tb, int newsize); |
28 | TString *luaS_newudata (lua_State *L, size_t s, void *udata); | ||
29 | TString *luaS_createudata (lua_State *L, void *udata, int tag); | 29 | TString *luaS_createudata (lua_State *L, void *udata, int tag); |
30 | void luaS_freeall (lua_State *L); | 30 | void luaS_freeall (lua_State *L); |
31 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l); | 31 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltable.c,v 1.56 2000/09/29 12:42:13 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.57 2000/10/05 12:14:08 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 | */ |
@@ -139,7 +139,7 @@ Node *luaH_next (lua_State *L, const Hash *t, const TObject *key) { | |||
139 | */ | 139 | */ |
140 | void luaH_remove (Hash *t, TObject *key) { | 140 | void luaH_remove (Hash *t, TObject *key) { |
141 | if (ttype(key) == LUA_TNUMBER || | 141 | if (ttype(key) == LUA_TNUMBER || |
142 | (ttype(key) == LUA_TSTRING && tsvalue(key)->u.s.len <= 30)) | 142 | (ttype(key) == LUA_TSTRING && tsvalue(key)->len <= 30)) |
143 | return; /* do not remove numbers nor small strings */ | 143 | return; /* do not remove numbers nor small strings */ |
144 | else { | 144 | else { |
145 | /* try to find a number `n' with the same hash as `key' */ | 145 | /* try to find a number `n' with the same hash as `key' */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.50 2000/10/06 19:29:26 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.51 2000/10/20 16:39:03 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 | */ |
@@ -260,7 +260,10 @@ static int unref (lua_State *L) { | |||
260 | } | 260 | } |
261 | 261 | ||
262 | static int newuserdata (lua_State *L) { | 262 | static int newuserdata (lua_State *L) { |
263 | lua_pushusertag(L, (void *)luaL_check_int(L, 1), luaL_check_int(L, 2)); | 263 | if (lua_isnumber(L, 2)) |
264 | lua_pushusertag(L, (void *)luaL_check_int(L, 1), luaL_check_int(L, 2)); | ||
265 | else | ||
266 | lua_newuserdata(L, luaL_check_int(L, 1)); | ||
264 | return 1; | 267 | return 1; |
265 | } | 268 | } |
266 | 269 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.75 2000/10/20 16:39:03 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.76 2000/10/24 19:12:06 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 |
@@ -182,6 +182,8 @@ LUA_API int lua_getn (lua_State *L, int index); | |||
182 | 182 | ||
183 | LUA_API void lua_concat (lua_State *L, int n); | 183 | LUA_API void lua_concat (lua_State *L, int n); |
184 | 184 | ||
185 | LUA_API void *lua_newuserdata (lua_State *L, size_t size); | ||
186 | |||
185 | 187 | ||
186 | /* | 188 | /* |
187 | ** =============================================================== | 189 | ** =============================================================== |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 1.144 2000/10/05 13:00:17 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.145 2000/10/06 12:45:25 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -249,9 +249,9 @@ static void call_arith (lua_State *L, StkId top, TMS event) { | |||
249 | 249 | ||
250 | static int luaV_strcomp (const TString *ls, const TString *rs) { | 250 | static int luaV_strcomp (const TString *ls, const TString *rs) { |
251 | const char *l = ls->str; | 251 | const char *l = ls->str; |
252 | size_t ll = ls->u.s.len; | 252 | size_t ll = ls->len; |
253 | const char *r = rs->str; | 253 | const char *r = rs->str; |
254 | size_t lr = rs->u.s.len; | 254 | size_t lr = rs->len; |
255 | for (;;) { | 255 | for (;;) { |
256 | int temp = strcoll(l, r); | 256 | int temp = strcoll(l, r); |
257 | if (temp != 0) return temp; | 257 | if (temp != 0) return temp; |
@@ -293,21 +293,21 @@ void luaV_strconc (lua_State *L, int total, StkId top) { | |||
293 | if (!call_binTM(L, top, TM_CONCAT)) | 293 | if (!call_binTM(L, top, TM_CONCAT)) |
294 | luaG_binerror(L, top-2, LUA_TSTRING, "concat"); | 294 | luaG_binerror(L, top-2, LUA_TSTRING, "concat"); |
295 | } | 295 | } |
296 | else if (tsvalue(top-1)->u.s.len > 0) { /* if len=0, do nothing */ | 296 | else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ |
297 | /* at least two string values; get as many as possible */ | 297 | /* at least two string values; get as many as possible */ |
298 | lint32 tl = (lint32)tsvalue(top-1)->u.s.len + | 298 | lint32 tl = (lint32)tsvalue(top-1)->len + |
299 | (lint32)tsvalue(top-2)->u.s.len; | 299 | (lint32)tsvalue(top-2)->len; |
300 | char *buffer; | 300 | char *buffer; |
301 | int i; | 301 | int i; |
302 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ | 302 | while (n < total && !tostring(L, top-n-1)) { /* collect total length */ |
303 | tl += tsvalue(top-n-1)->u.s.len; | 303 | tl += tsvalue(top-n-1)->len; |
304 | n++; | 304 | n++; |
305 | } | 305 | } |
306 | if (tl > MAX_SIZET) lua_error(L, "string size overflow"); | 306 | if (tl > MAX_SIZET) lua_error(L, "string size overflow"); |
307 | buffer = luaO_openspace(L, tl); | 307 | buffer = luaO_openspace(L, tl); |
308 | tl = 0; | 308 | tl = 0; |
309 | for (i=n; i>0; i--) { /* concat all strings */ | 309 | for (i=n; i>0; i--) { /* concat all strings */ |
310 | size_t l = tsvalue(top-i)->u.s.len; | 310 | size_t l = tsvalue(top-i)->len; |
311 | memcpy(buffer+tl, tsvalue(top-i)->str, l); | 311 | memcpy(buffer+tl, tsvalue(top-i)->str, l); |
312 | tl += l; | 312 | tl += l; |
313 | } | 313 | } |