diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-17 19:23:43 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-17 19:23:43 -0200 |
| commit | 1929ddcf49b948ed8082cd375f7f7bf0b8a15bee (patch) | |
| tree | 9578d04056107bea60dee410d3889d7745d8764d | |
| parent | aa4cd37adfdeb84b8137d3fccdb28a49a3b6d9e5 (diff) | |
| download | lua-1929ddcf49b948ed8082cd375f7f7bf0b8a15bee.tar.gz lua-1929ddcf49b948ed8082cd375f7f7bf0b8a15bee.tar.bz2 lua-1929ddcf49b948ed8082cd375f7f7bf0b8a15bee.zip | |
userdata can have different tags
| -rw-r--r-- | hash.c | 10 | ||||
| -rw-r--r-- | lua.h | 21 | ||||
| -rw-r--r-- | opcode.c | 9 |
3 files changed, 21 insertions, 19 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** hash manager for lua | 3 | ** hash manager for lua |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_hash="$Id: hash.c,v 2.17 1994/11/16 17:38:08 roberto Exp roberto $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.18 1994/11/17 13:58:57 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include "mem.h" | 8 | #include "mem.h" |
| 9 | #include "opcode.h" | 9 | #include "opcode.h" |
| @@ -49,6 +49,9 @@ static int hashindex (Hash *t, Object *ref) /* hash function */ | |||
| 49 | { | 49 | { |
| 50 | switch (tag(ref)) | 50 | switch (tag(ref)) |
| 51 | { | 51 | { |
| 52 | case LUA_T_NIL: | ||
| 53 | lua_reportbug ("unexpected type to index table"); | ||
| 54 | return -1; /* UNREACHEABLE */ | ||
| 52 | case LUA_T_NUMBER: | 55 | case LUA_T_NUMBER: |
| 53 | return (((int)nvalue(ref))%nhash(t)); | 56 | return (((int)nvalue(ref))%nhash(t)); |
| 54 | case LUA_T_STRING: | 57 | case LUA_T_STRING: |
| @@ -69,11 +72,8 @@ static int hashindex (Hash *t, Object *ref) /* hash function */ | |||
| 69 | return (((int)fvalue(ref))%nhash(t)); | 72 | return (((int)fvalue(ref))%nhash(t)); |
| 70 | case LUA_T_ARRAY: | 73 | case LUA_T_ARRAY: |
| 71 | return (((int)avalue(ref))%nhash(t)); | 74 | return (((int)avalue(ref))%nhash(t)); |
| 72 | case LUA_T_USERDATA: | 75 | default: /* user data */ |
| 73 | return (((int)uvalue(ref))%nhash(t)); | 76 | return (((int)uvalue(ref))%nhash(t)); |
| 74 | default: | ||
| 75 | lua_reportbug ("unexpected type to index table"); | ||
| 76 | return -1; /* UNREACHEABLE */ | ||
| 77 | } | 77 | } |
| 78 | } | 78 | } |
| 79 | 79 | ||
| @@ -2,7 +2,7 @@ | |||
| 2 | ** LUA - Linguagem para Usuarios de Aplicacao | 2 | ** LUA - Linguagem para Usuarios de Aplicacao |
| 3 | ** Grupo de Tecnologia em Computacao Grafica | 3 | ** Grupo de Tecnologia em Computacao Grafica |
| 4 | ** TeCGraf - PUC-Rio | 4 | ** TeCGraf - PUC-Rio |
| 5 | ** $Id: lua.h,v 3.7 1994/11/13 16:17:04 roberto Exp $ | 5 | ** $Id: lua.h,v 3.8 1994/11/17 16:41:42 roberto Exp roberto $ |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | 8 | ||
| @@ -13,14 +13,13 @@ | |||
| 13 | 13 | ||
| 14 | typedef enum | 14 | typedef enum |
| 15 | { | 15 | { |
| 16 | LUA_T_MARK, | 16 | LUA_T_NIL = -1, |
| 17 | LUA_T_NIL, | 17 | LUA_T_NUMBER = -2, |
| 18 | LUA_T_NUMBER, | 18 | LUA_T_STRING = -3, |
| 19 | LUA_T_STRING, | 19 | LUA_T_ARRAY = -4, |
| 20 | LUA_T_ARRAY, | 20 | LUA_T_FUNCTION = -5, |
| 21 | LUA_T_FUNCTION, | 21 | LUA_T_CFUNCTION= -6, |
| 22 | LUA_T_CFUNCTION, | 22 | LUA_T_USERDATA = 0 |
| 23 | LUA_T_USERDATA | ||
| 24 | } lua_Type; | 23 | } lua_Type; |
| 25 | 24 | ||
| 26 | 25 | ||
| @@ -53,7 +52,7 @@ int lua_pushnil (void); | |||
| 53 | int lua_pushnumber (float n); | 52 | int lua_pushnumber (float n); |
| 54 | int lua_pushstring (char *s); | 53 | int lua_pushstring (char *s); |
| 55 | int lua_pushcfunction (lua_CFunction fn); | 54 | int lua_pushcfunction (lua_CFunction fn); |
| 56 | int lua_pushuserdata (void *u); | 55 | int lua_pushusertag (void *u, int tag); |
| 57 | int lua_pushobject (lua_Object object); | 56 | int lua_pushobject (lua_Object object); |
| 58 | 57 | ||
| 59 | lua_Object lua_getglobal (char *name); | 58 | lua_Object lua_getglobal (char *name); |
| @@ -77,6 +76,8 @@ lua_Object lua_createTable (int initSize); | |||
| 77 | #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript()) | 76 | #define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript()) |
| 78 | #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_getsubscript()) | 77 | #define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_getsubscript()) |
| 79 | 78 | ||
| 79 | #define lua_pushuserdata(u) lua_pushusertag(u,LUA_USERDATA) | ||
| 80 | |||
| 80 | #define lua_isnil(_) (lua_type(_)==LUA_T_NIL) | 81 | #define lua_isnil(_) (lua_type(_)==LUA_T_NIL) |
| 81 | #define lua_isnumber(_) (lua_type(_)==LUA_T_NUMBER) | 82 | #define lua_isnumber(_) (lua_type(_)==LUA_T_NUMBER) |
| 82 | #define lua_isstring(_) (lua_type(_)==LUA_T_STRING) | 83 | #define lua_isstring(_) (lua_type(_)==LUA_T_STRING) |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_opcode="$Id: opcode.c,v 3.15 1994/11/17 16:41:42 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.16 1994/11/17 19:43:34 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -536,7 +536,7 @@ lua_CFunction lua_getcfunction (lua_Object object) | |||
| 536 | void *lua_getuserdata (lua_Object object) | 536 | void *lua_getuserdata (lua_Object object) |
| 537 | { | 537 | { |
| 538 | if (object == 0) return NULL; | 538 | if (object == 0) return NULL; |
| 539 | if (tag(Address(object)) != LUA_T_USERDATA) return NULL; | 539 | if (tag(Address(object)) < LUA_T_USERDATA) return NULL; |
| 540 | else return (uvalue(Address(object))); | 540 | else return (uvalue(Address(object))); |
| 541 | } | 541 | } |
| 542 | 542 | ||
| @@ -621,10 +621,11 @@ int lua_pushcfunction (lua_CFunction fn) | |||
| 621 | /* | 621 | /* |
| 622 | ** Push an object (tag=userdata) to stack. Return 0 on success or 1 on error. | 622 | ** Push an object (tag=userdata) to stack. Return 0 on success or 1 on error. |
| 623 | */ | 623 | */ |
| 624 | int lua_pushuserdata (void *u) | 624 | int lua_pushusertag (void *u, int tag) |
| 625 | { | 625 | { |
| 626 | lua_checkstack(top-stack+1); | 626 | lua_checkstack(top-stack+1); |
| 627 | tag(top) = LUA_T_USERDATA; uvalue(top++) = u; | 627 | if (tag < LUA_T_USERDATA) return 1; |
| 628 | tag(top) = tag; uvalue(top++) = u; | ||
| 628 | return 0; | 629 | return 0; |
| 629 | } | 630 | } |
| 630 | 631 | ||
