diff options
| -rw-r--r-- | lapi.c | 15 | ||||
| -rw-r--r-- | lauxlib.c | 3 | ||||
| -rw-r--r-- | lbuiltin.c | 20 | ||||
| -rw-r--r-- | ldo.c | 22 | ||||
| -rw-r--r-- | ldo.h | 4 | ||||
| -rw-r--r-- | liolib.c | 4 | ||||
| -rw-r--r-- | llex.c | 17 | ||||
| -rw-r--r-- | llex.h | 4 | ||||
| -rw-r--r-- | lmathlib.c | 4 | ||||
| -rw-r--r-- | lstring.c | 28 | ||||
| -rw-r--r-- | lstring.h | 4 | ||||
| -rw-r--r-- | ltm.c | 83 | ||||
| -rw-r--r-- | ltm.h | 3 | ||||
| -rw-r--r-- | lua.h | 9 |
14 files changed, 87 insertions, 133 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.3 1997/10/24 17:17:24 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 | */ |
| @@ -10,9 +10,11 @@ | |||
| 10 | 10 | ||
| 11 | #include "lapi.h" | 11 | #include "lapi.h" |
| 12 | #include "lauxlib.h" | 12 | #include "lauxlib.h" |
| 13 | #include "lbuiltin.h" | ||
| 13 | #include "ldo.h" | 14 | #include "ldo.h" |
| 14 | #include "lfunc.h" | 15 | #include "lfunc.h" |
| 15 | #include "lgc.h" | 16 | #include "lgc.h" |
| 17 | #include "llex.h" | ||
| 16 | #include "lmem.h" | 18 | #include "lmem.h" |
| 17 | #include "lobject.h" | 19 | #include "lobject.h" |
| 18 | #include "lstring.h" | 20 | #include "lstring.h" |
| @@ -544,6 +546,17 @@ lua_Object lua_getref (int ref) | |||
| 544 | } | 546 | } |
| 545 | 547 | ||
| 546 | 548 | ||
| 549 | void lua_open (void) | ||
| 550 | { | ||
| 551 | static int firsttime = 1; | ||
| 552 | if (!firsttime) return; | ||
| 553 | firsttime = 0; | ||
| 554 | luaS_init(); | ||
| 555 | luaX_init(); | ||
| 556 | luaT_init(); | ||
| 557 | luaD_init(); | ||
| 558 | luaB_predefine(); | ||
| 559 | } | ||
| 547 | 560 | ||
| 548 | 561 | ||
| 549 | 562 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ |
| 3 | ** Auxiliar functions for building Lua libraries | 3 | ** Auxiliar functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -67,6 +67,7 @@ lua_Object luaL_nonnullarg (int numArg) | |||
| 67 | void luaL_openlib (struct luaL_reg *l, int n) | 67 | void luaL_openlib (struct luaL_reg *l, int n) |
| 68 | { | 68 | { |
| 69 | int i; | 69 | int i; |
| 70 | lua_open(); /* make sure lua is already open */ | ||
| 70 | for (i=0; i<n; i++) | 71 | for (i=0; i<n; i++) |
| 71 | lua_register(l[i].name, l[i].func); | 72 | lua_register(l[i].name, l[i].func); |
| 72 | } | 73 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbuiltin.c,v 1.4 1997/10/23 16:28:48 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.5 1997/10/24 17:17:24 roberto Exp roberto $ |
| 3 | ** Built-in functions | 3 | ** Built-in functions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -455,23 +455,11 @@ static struct luaL_reg int_funcs[] = { | |||
| 455 | 455 | ||
| 456 | void luaB_predefine (void) | 456 | void luaB_predefine (void) |
| 457 | { | 457 | { |
| 458 | int i; | ||
| 459 | TaggedString *ts; | ||
| 460 | TObject o; | ||
| 461 | /* pre-register mem error messages, to avoid loop when error arises */ | 458 | /* pre-register mem error messages, to avoid loop when error arises */ |
| 462 | luaS_newfixedstring(tableEM); | 459 | luaS_newfixedstring(tableEM); |
| 463 | luaS_newfixedstring(memEM); | 460 | luaS_newfixedstring(memEM); |
| 464 | for (i=0; i<INTFUNCSIZE; i++) { | 461 | luaL_openlib(int_funcs, (sizeof(int_funcs)/sizeof(int_funcs[0]))); |
| 465 | ts = luaS_new(int_funcs[i].name); | 462 | lua_pushstring(LUA_VERSION); |
| 466 | fvalue(&o) = int_funcs[i].func; | 463 | lua_setglobal("_VERSION"); |
| 467 | ttype(&o) = LUA_T_CPROTO; | ||
| 468 | luaF_simpleclosure(&o); | ||
| 469 | luaS_rawsetglobal(ts, &o); | ||
| 470 | } | ||
| 471 | ts = luaS_new("_VERSION"); | ||
| 472 | ttype(&o) = LUA_T_STRING; | ||
| 473 | tsvalue(&o) = luaS_new(LUA_VERSION); | ||
| 474 | luaS_rawsetglobal(ts, &o); | ||
| 475 | } | 464 | } |
| 476 | 465 | ||
| 477 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.5 1997/10/24 17:17:24 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.6 1997/11/03 21:00:23 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -9,7 +9,6 @@ | |||
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| 10 | #include <string.h> | 10 | #include <string.h> |
| 11 | 11 | ||
| 12 | #include "lbuiltin.h" | ||
| 13 | #include "ldo.h" | 12 | #include "ldo.h" |
| 14 | #include "lfunc.h" | 13 | #include "lfunc.h" |
| 15 | #include "lgc.h" | 14 | #include "lgc.h" |
| @@ -30,9 +29,7 @@ | |||
| 30 | #endif | 29 | #endif |
| 31 | 30 | ||
| 32 | 31 | ||
| 33 | static TObject initial_stack; | 32 | struct Stack luaD_stack; |
| 34 | |||
| 35 | struct Stack luaD_stack = {&initial_stack, &initial_stack, &initial_stack}; | ||
| 36 | 33 | ||
| 37 | 34 | ||
| 38 | struct C_Lua_Stack luaD_Cstack = {0, 0, 0}; | 35 | struct C_Lua_Stack luaD_Cstack = {0, 0, 0}; |
| @@ -64,24 +61,21 @@ static void initCfunc (TObject *o, lua_CFunction f) | |||
| 64 | 61 | ||
| 65 | 62 | ||
| 66 | #define STACK_EXTRA 32 | 63 | #define STACK_EXTRA 32 |
| 64 | #define INIT_STACK_SIZE 32 | ||
| 65 | |||
| 67 | 66 | ||
| 68 | static void initstack (int n) | 67 | void luaD_init (void) |
| 69 | { | 68 | { |
| 70 | int maxstack = STACK_EXTRA+n; | 69 | luaD_stack.stack = luaM_newvector(INIT_STACK_SIZE, TObject); |
| 71 | luaD_stack.stack = luaM_newvector(maxstack, TObject); | ||
| 72 | luaD_stack.last = luaD_stack.stack+(maxstack-1); | ||
| 73 | luaD_stack.top = luaD_stack.stack; | 70 | luaD_stack.top = luaD_stack.stack; |
| 74 | *luaD_stack.stack = initial_stack; | 71 | luaD_stack.last = luaD_stack.stack+(INIT_STACK_SIZE-1); |
| 75 | luaB_predefine(); | ||
| 76 | initCfunc(&luaD_errorim, stderrorim); | 72 | initCfunc(&luaD_errorim, stderrorim); |
| 77 | } | 73 | } |
| 78 | 74 | ||
| 79 | 75 | ||
| 80 | void luaD_checkstack (int n) | 76 | void luaD_checkstack (int n) |
| 81 | { | 77 | { |
| 82 | if (luaD_stack.stack == &initial_stack) | 78 | if (luaD_stack.last-luaD_stack.top <= n) { |
| 83 | initstack(n); | ||
| 84 | else if (luaD_stack.last-luaD_stack.top <= n) { | ||
| 85 | static int limit = STACK_LIMIT; | 79 | static int limit = STACK_LIMIT; |
| 86 | StkId top = luaD_stack.top-luaD_stack.stack; | 80 | StkId top = luaD_stack.top-luaD_stack.stack; |
| 87 | int stacksize = (luaD_stack.last-luaD_stack.stack)+1+STACK_EXTRA+n; | 81 | int stacksize = (luaD_stack.last-luaD_stack.stack)+1+STACK_EXTRA+n; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: $ | 2 | ** $Id: ldo.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -47,6 +47,8 @@ extern TObject luaD_errorim; | |||
| 47 | #define Address(lo) ((lo)+luaD_stack.stack-1) | 47 | #define Address(lo) ((lo)+luaD_stack.stack-1) |
| 48 | #define Ref(st) ((st)-luaD_stack.stack+1) | 48 | #define Ref(st) ((st)-luaD_stack.stack+1) |
| 49 | 49 | ||
| 50 | |||
| 51 | void luaD_init (void); | ||
| 50 | void luaD_adjusttop (StkId newtop); | 52 | void luaD_adjusttop (StkId newtop); |
| 51 | void luaD_openstack (int nelems); | 53 | void luaD_openstack (int nelems); |
| 52 | void luaD_lineHook (int line); | 54 | void luaD_lineHook (int line); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.2 1997/09/23 14:12:44 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.3 1997/10/30 20:29:09 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 | */ |
| @@ -372,6 +372,7 @@ static struct luaL_reg iolib[] = { | |||
| 372 | 372 | ||
| 373 | void lua_iolibopen (void) | 373 | void lua_iolibopen (void) |
| 374 | { | 374 | { |
| 375 | luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0]))); | ||
| 375 | lua_tagio = lua_newtag(); | 376 | lua_tagio = lua_newtag(); |
| 376 | closedtag = lua_newtag(); | 377 | closedtag = lua_newtag(); |
| 377 | setfile(stdin, "_INPUT"); | 378 | setfile(stdin, "_INPUT"); |
| @@ -379,7 +380,6 @@ void lua_iolibopen (void) | |||
| 379 | setfile(stdin, "_STDIN"); | 380 | setfile(stdin, "_STDIN"); |
| 380 | setfile(stdout, "_STDOUT"); | 381 | setfile(stdout, "_STDOUT"); |
| 381 | setfile(stderr, "_STDERR"); | 382 | setfile(stderr, "_STDERR"); |
| 382 | luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0]))); | ||
| 383 | lua_pushcfunction(errorfb); | 383 | lua_pushcfunction(errorfb); |
| 384 | lua_seterrormethod(); | 384 | lua_seterrormethod(); |
| 385 | } | 385 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.3 1997/10/13 22:10:45 roberto Exp roberto $ |
| 3 | ** Lexical Analizer | 3 | ** Lexical Analizer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -30,7 +30,7 @@ int lua_debug=0; | |||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | static void addReserved (void) | 33 | void luaX_init (void) |
| 34 | { | 34 | { |
| 35 | static struct { | 35 | static struct { |
| 36 | char *name; | 36 | char *name; |
| @@ -41,14 +41,10 @@ static void addReserved (void) | |||
| 41 | {"nil", NIL}, {"not", NOT}, {"or", OR}, {"repeat", REPEAT}, | 41 | {"nil", NIL}, {"not", NOT}, {"or", OR}, {"repeat", REPEAT}, |
| 42 | {"return", RETURN}, {"then", THEN}, {"until", UNTIL}, {"while", WHILE} | 42 | {"return", RETURN}, {"then", THEN}, {"until", UNTIL}, {"while", WHILE} |
| 43 | }; | 43 | }; |
| 44 | static int firsttime = 1; | 44 | int i; |
| 45 | if (firsttime) { | 45 | for (i=0; i<(sizeof(reserved)/sizeof(reserved[0])); i++) { |
| 46 | int i; | 46 | TaggedString *ts = luaS_new(reserved[i].name); |
| 47 | firsttime = 0; | 47 | ts->head.marked = reserved[i].token; /* reserved word (always > 255) */ |
| 48 | for (i=0; i<(sizeof(reserved)/sizeof(reserved[0])); i++) { | ||
| 49 | TaggedString *ts = luaS_new(reserved[i].name); | ||
| 50 | ts->head.marked = reserved[i].token; /* reserved word (always > 255) */ | ||
| 51 | } | ||
| 52 | } | 48 | } |
| 53 | } | 49 | } |
| 54 | 50 | ||
| @@ -85,7 +81,6 @@ static void firstline (void) | |||
| 85 | 81 | ||
| 86 | void luaX_setinput (ZIO *z) | 82 | void luaX_setinput (ZIO *z) |
| 87 | { | 83 | { |
| 88 | addReserved(); | ||
| 89 | current = '\n'; | 84 | current = '\n'; |
| 90 | luaX_linenumber = 0; | 85 | luaX_linenumber = 0; |
| 91 | iflevel = 0; | 86 | iflevel = 0; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: $ | 2 | ** $Id: llex.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ |
| 3 | ** Lexical Analizer | 3 | ** Lexical Analizer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -13,6 +13,8 @@ | |||
| 13 | 13 | ||
| 14 | extern int luaX_linenumber; | 14 | extern int luaX_linenumber; |
| 15 | 15 | ||
| 16 | |||
| 17 | void luaX_init (void); | ||
| 16 | int luaY_lex (void); | 18 | int luaY_lex (void); |
| 17 | void luaX_setinput (ZIO *z); | 19 | void luaX_setinput (ZIO *z); |
| 18 | char *luaX_lasttoken (void); | 20 | char *luaX_lasttoken (void); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.2 1997/10/24 17:44:22 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.3 1997/11/03 21:11:44 roberto Exp roberto $ |
| 3 | ** Lua standard mathematical library | 3 | ** Lua standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -202,8 +202,8 @@ static struct luaL_reg mathlib[] = { | |||
| 202 | */ | 202 | */ |
| 203 | void lua_mathlibopen (void) | 203 | void lua_mathlibopen (void) |
| 204 | { | 204 | { |
| 205 | lua_pushstring("deg"); lua_setglobal("_TRIGMODE"); | ||
| 206 | luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); | 205 | luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); |
| 206 | lua_pushstring("deg"); lua_setglobal("_TRIGMODE"); | ||
| 207 | lua_pushcfunction(math_pow); | 207 | lua_pushcfunction(math_pow); |
| 208 | lua_pushnumber(0); /* to get its tag */ | 208 | lua_pushnumber(0); /* to get its tag */ |
| 209 | lua_settagmethod(lua_tag(lua_pop()), "pow"); | 209 | lua_settagmethod(lua_tag(lua_pop()), "pow"); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.3 1997/10/23 16:26:37 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 | */ |
| @@ -29,26 +29,22 @@ typedef struct { | |||
| 29 | } stringtable; | 29 | } stringtable; |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | static stringtable string_root[NUM_HASHS] = { | 32 | static stringtable string_root[NUM_HASHS]; |
| 33 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 34 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 35 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 36 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 37 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 38 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 39 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 40 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 41 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 42 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 43 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 44 | {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, {0, 0, NULL}, | ||
| 45 | {0, 0, NULL} | ||
| 46 | }; | ||
| 47 | 33 | ||
| 48 | 34 | ||
| 49 | static TaggedString EMPTY = {{NULL, 2}, 0, 0L, {{LUA_T_NIL, {NULL}}}, {0}}; | 35 | static TaggedString EMPTY = {{NULL, 2}, 0, 0L, {{LUA_T_NIL, {NULL}}}, {0}}; |
| 50 | 36 | ||
| 51 | 37 | ||
| 38 | void luaS_init (void) | ||
| 39 | { | ||
| 40 | int i; | ||
| 41 | for (i=0; i<NUM_HASHS; i++) { | ||
| 42 | string_root[i].size = 0; | ||
| 43 | string_root[i].nuse = 0; | ||
| 44 | string_root[i].hash = NULL; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 52 | 48 | ||
| 53 | static unsigned long hash (char *s, int tag) | 49 | static unsigned long hash (char *s, int tag) |
| 54 | { | 50 | { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ | 2 | ** $Id: lstring.h,v 1.2 1997/09/26 15:02:26 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 | */ |
| @@ -12,6 +12,8 @@ | |||
| 12 | 12 | ||
| 13 | extern GCnode luaS_root; | 13 | extern GCnode luaS_root; |
| 14 | 14 | ||
| 15 | |||
| 16 | void luaS_init (void); | ||
| 15 | TaggedString *luaS_createudata (void *udata, int tag); | 17 | TaggedString *luaS_createudata (void *udata, int tag); |
| 16 | TaggedString *luaS_collector (void); | 18 | TaggedString *luaS_collector (void); |
| 17 | void luaS_free (TaggedString *l); | 19 | void luaS_free (TaggedString *l); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 1.4 1997/10/24 17:17:24 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.5 1997/11/03 20:45:23 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 | */ |
| @@ -14,53 +14,6 @@ | |||
| 14 | #include "lobject.h" | 14 | #include "lobject.h" |
| 15 | #include "ltm.h" | 15 | #include "ltm.h" |
| 16 | 16 | ||
| 17 | static struct IM init_IM[NUM_TAGS] = { | ||
| 18 | {{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 19 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 20 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 21 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 22 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 23 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}}, | ||
| 24 | {{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 25 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 26 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 27 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 28 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 29 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}}, | ||
| 30 | {{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 31 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 32 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 33 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 34 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 35 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}}, | ||
| 36 | {{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 37 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 38 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 39 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 40 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 41 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}}, | ||
| 42 | {{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 43 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 44 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 45 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 46 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 47 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}}, | ||
| 48 | {{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 49 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 50 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 51 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 52 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 53 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}}, | ||
| 54 | {{{LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 55 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 56 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 57 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 58 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, | ||
| 59 | {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}, {LUA_T_NIL, {NULL}}}} | ||
| 60 | }; | ||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | 17 | ||
| 65 | char *luaT_eventname[] = { /* ORDER IM */ | 18 | char *luaT_eventname[] = { /* ORDER IM */ |
| 66 | "gettable", "settable", "index", "getglobal", "setglobal", "add", | 19 | "gettable", "settable", "index", "getglobal", "setglobal", "add", |
| @@ -78,11 +31,9 @@ static int luaI_checkevent (char *name, char *list[]) | |||
| 78 | } | 31 | } |
| 79 | 32 | ||
| 80 | 33 | ||
| 81 | struct IM *luaT_IMtable = init_IM; | 34 | struct IM *luaT_IMtable; |
| 82 | 35 | static int IMtable_size; | |
| 83 | static int IMtable_size = NUM_TAGS; | 36 | static int last_tag; |
| 84 | |||
| 85 | static int last_tag = -(NUM_TAGS-1); | ||
| 86 | 37 | ||
| 87 | 38 | ||
| 88 | /* events in LUA_T_NIL are all allowed, since this is used as a | 39 | /* events in LUA_T_NIL are all allowed, since this is used as a |
| @@ -98,6 +49,7 @@ static char validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */ | |||
| 98 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */ | 49 | {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */ |
| 99 | }; | 50 | }; |
| 100 | 51 | ||
| 52 | |||
| 101 | static int validevent (lua_Type t, int e) | 53 | static int validevent (lua_Type t, int e) |
| 102 | { /* ORDER LUA_T */ | 54 | { /* ORDER LUA_T */ |
| 103 | return (t < LUA_T_NIL) ? 1 : validevents[-t][e]; | 55 | return (t < LUA_T_NIL) ? 1 : validevents[-t][e]; |
| @@ -111,19 +63,24 @@ static void init_entry (int tag) | |||
| 111 | ttype(luaT_getim(tag, i)) = LUA_T_NIL; | 63 | ttype(luaT_getim(tag, i)) = LUA_T_NIL; |
| 112 | } | 64 | } |
| 113 | 65 | ||
| 66 | |||
| 67 | void luaT_init (void) | ||
| 68 | { | ||
| 69 | int t; | ||
| 70 | IMtable_size = NUM_TAGS; | ||
| 71 | last_tag = -(NUM_TAGS-1); | ||
| 72 | luaT_IMtable = luaM_newvector(IMtable_size, struct IM); | ||
| 73 | for (t=last_tag; t<=0; t++) | ||
| 74 | init_entry(t); | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 114 | int lua_newtag (void) | 78 | int lua_newtag (void) |
| 115 | { | 79 | { |
| 116 | --last_tag; | 80 | --last_tag; |
| 117 | if ((-last_tag) >= IMtable_size) { | 81 | if ((-last_tag) >= IMtable_size) |
| 118 | if (luaT_IMtable == init_IM) { /* fist time? */ | 82 | IMtable_size = luaM_growvector(&luaT_IMtable, IMtable_size, |
| 119 | IMtable_size *= 2; | 83 | struct IM, memEM, MAX_INT); |
| 120 | luaT_IMtable = luaM_newvector(IMtable_size, struct IM); | ||
| 121 | memcpy(luaT_IMtable, init_IM, sizeof(init_IM)); | ||
| 122 | } | ||
| 123 | else | ||
| 124 | IMtable_size = luaM_growvector(&luaT_IMtable, IMtable_size, | ||
| 125 | struct IM, memEM, MAX_INT); | ||
| 126 | } | ||
| 127 | init_entry(last_tag); | 84 | init_entry(last_tag); |
| 128 | return last_tag; | 85 | return last_tag; |
| 129 | } | 86 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: $ | 2 | ** $Id: ltm.h,v 1.1 1997/09/16 19:25:59 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 | */ |
| @@ -49,6 +49,7 @@ extern struct IM { | |||
| 49 | extern char *luaT_eventname[]; | 49 | extern char *luaT_eventname[]; |
| 50 | 50 | ||
| 51 | 51 | ||
| 52 | void luaT_init (void); | ||
| 52 | void luaT_settag (int tag, TObject *o); | 53 | void luaT_settag (int tag, TObject *o); |
| 53 | void luaT_realtag (int tag); | 54 | void luaT_realtag (int tag); |
| 54 | int luaT_efectivetag (TObject *o); | 55 | int luaT_efectivetag (TObject *o); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.2 1997/10/24 17:17:24 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 |
| @@ -53,9 +53,12 @@ | |||
| 53 | typedef void (*lua_CFunction) (void); | 53 | typedef void (*lua_CFunction) (void); |
| 54 | typedef unsigned int lua_Object; | 54 | typedef unsigned int lua_Object; |
| 55 | 55 | ||
| 56 | lua_Object lua_settagmethod (int tag, char *event); /* In: luaM_new method */ | 56 | |
| 57 | void lua_open (void); | ||
| 58 | |||
| 59 | lua_Object lua_settagmethod (int tag, char *event); /* In: new method */ | ||
| 57 | lua_Object lua_gettagmethod (int tag, char *event); | 60 | lua_Object lua_gettagmethod (int tag, char *event); |
| 58 | lua_Object lua_seterrormethod (void); /* In: luaM_new method */ | 61 | lua_Object lua_seterrormethod (void); /* In: new method */ |
| 59 | 62 | ||
| 60 | int lua_newtag (void); | 63 | int lua_newtag (void); |
| 61 | void lua_settag (int tag); /* In: object */ | 64 | void lua_settag (int tag); /* In: object */ |
