diff --git a/engine/lua/lapi.cpp b/engine/lua/lapi.cpp index 261bbc8a4b6..934c52cd53f 100644 --- a/engine/lua/lapi.cpp +++ b/engine/lua/lapi.cpp @@ -5,9 +5,6 @@ */ -#include -#include - #include "lapi.h" #include "lauxlib.h" #include "ldo.h" @@ -35,9 +32,9 @@ TObject *luaA_Address (lua_Object o) } -static int normalized_type (TObject *o) +static int32 normalized_type (TObject *o) { - int t = ttype(o); + int32 t = ttype(o); switch (t) { case LUA_T_PMARK: return LUA_T_PROTO; @@ -71,7 +68,7 @@ void luaA_packresults (void) } -int luaA_passresults (void) +int32 luaA_passresults (void) { luaD_checkstack(L->Cstack.num); memcpy(L->stack.top, L->Cstack.lua2C+L->stack.stack, @@ -81,7 +78,7 @@ int luaA_passresults (void) } -static void checkCparams (int nParams) +static void checkCparams (int32 nParams) { if (L->stack.top-L->stack.stack < L->Cstack.base+nParams) lua_error("API error - wrong number of arguments in C2lua stack"); @@ -115,7 +112,7 @@ lua_Object lua_pop (void) ** Get a parameter, returning the object handle or LUA_NOOBJECT on error. ** 'number' must be 1 to get the first parameter. */ -lua_Object lua_lua2C (int number) +lua_Object lua_lua2C (int32 number) { if (number <= 0 || number > L->Cstack.num) return LUA_NOOBJECT; /* Ref(L->stack.stack+(L->Cstack.lua2C+number-1)) == @@ -124,7 +121,7 @@ lua_Object lua_lua2C (int number) } -int lua_callfunction (lua_Object function) +int32 lua_callfunction (lua_Object function) { if (function == LUA_NOOBJECT) return 1; @@ -136,13 +133,13 @@ int lua_callfunction (lua_Object function) } -lua_Object lua_gettagmethod (int tag, const char *event) +lua_Object lua_gettagmethod (int32 tag, const char *event) { return put_luaObject(luaT_gettagmethod(tag, event)); } -lua_Object lua_settagmethod (int tag, const char *event) +lua_Object lua_settagmethod (int32 tag, const char *event) { checkCparams(1); luaT_settagmethod(tag, event, L->stack.top-1); @@ -240,40 +237,40 @@ void lua_rawsetglobal (const char *name) -int lua_isnil (lua_Object o) +int32 lua_isnil (lua_Object o) { return (o == LUA_NOOBJECT) || (ttype(Address(o)) == LUA_T_NIL); } -int lua_istable (lua_Object o) +int32 lua_istable (lua_Object o) { return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_ARRAY); } -int lua_isuserdata (lua_Object o) +int32 lua_isuserdata (lua_Object o) { return (o!= LUA_NOOBJECT) && (ttype(Address(o)) == LUA_T_USERDATA); } -int lua_iscfunction (lua_Object o) +int32 lua_iscfunction (lua_Object o) { return (lua_tag(o) == LUA_T_CPROTO); } -int lua_isnumber (lua_Object o) +int32 lua_isnumber (lua_Object o) { return (o!= LUA_NOOBJECT) && (tonumber(Address(o)) == 0); } -int lua_isstring (lua_Object o) +int32 lua_isstring (lua_Object o) { - int t = lua_tag(o); + int32 t = lua_tag(o); return (t == LUA_T_STRING) || (t == LUA_T_NUMBER); } -int lua_isfunction (lua_Object o) +int32 lua_isfunction (lua_Object o) { - int t = lua_tag(o); + int32 t = lua_tag(o); return (t == LUA_T_PROTO) || (t == LUA_T_CPROTO); } @@ -293,11 +290,11 @@ const char *lua_getstring (lua_Object object) else return (svalue(Address(object))); } -long lua_strlen (lua_Object object) +int32 lua_strlen (lua_Object object) { luaC_checkGC(); /* "tostring" may create a new string */ if (object == LUA_NOOBJECT || tostring(Address(object))) - return 0L; + return 0; else return (tsvalue(Address(object))->u.s.len); } @@ -329,7 +326,7 @@ void lua_pushnumber (double n) incr_top; } -void lua_pushlstring (const char *s, long len) +void lua_pushlstring (const char *s, int32 len) { tsvalue(L->stack.top) = luaS_newlstr(s, len); ttype(L->stack.top) = LUA_T_STRING; @@ -345,7 +342,7 @@ void lua_pushstring (const char *s) lua_pushlstring(s, strlen(s)); } -void lua_pushcclosure (lua_CFunction fn, int n) +void lua_pushcclosure (lua_CFunction fn, int32 n) { if (fn == NULL) lua_error("API error - attempt to push a NULL Cfunction"); @@ -357,7 +354,7 @@ void lua_pushcclosure (lua_CFunction fn, int n) luaC_checkGC(); } -void lua_pushusertag (void *u, int tag) +void lua_pushusertag (void *u, int32 tag) { if (tag < 0 && tag != LUA_ANYTAG) luaT_realtag(tag); /* error if tag is not valid */ @@ -384,13 +381,13 @@ void lua_pushobject (lua_Object o) } -int lua_tag (lua_Object lo) +int32 lua_tag (lua_Object lo) { if (lo == LUA_NOOBJECT) return LUA_T_NIL; else { TObject *o = Address(lo); - int t; + int32 t; switch (t = ttype(o)) { case LUA_T_USERDATA: return o->value.ts->u.d.tag; @@ -413,7 +410,7 @@ int lua_tag (lua_Object lo) } -void lua_settag (int tag) +void lua_settag (int32 tag) { checkCparams(1); luaT_realtag(tag); @@ -444,11 +441,11 @@ lua_CHFunction lua_callhook = NULL; lua_LHFunction lua_linehook = NULL; -lua_Function lua_stackedfunction (int level) +lua_Function lua_stackedfunction (int32 level) { StkId i; for (i = (L->stack.top-1)-L->stack.stack; i>=0; i--) { - int t = L->stack.stack[i].ttype; + int32 t = L->stack.stack[i].ttype; if (t == LUA_T_CLMARK || t == LUA_T_PMARK || t == LUA_T_CMARK) if (level-- == 0) return Ref(L->stack.stack+i); @@ -457,7 +454,7 @@ lua_Function lua_stackedfunction (int level) } -int lua_currentline (lua_Function func) +int32 lua_currentline (lua_Function func) { TObject *f = Address(func); return (f+1 < L->stack.top && (f+1)->ttype == LUA_T_LINE) ? @@ -465,7 +462,7 @@ int lua_currentline (lua_Function func) } -lua_Object lua_getlocal (lua_Function func, int local_number, char **name) +lua_Object lua_getlocal (lua_Function func, int32 local_number, char **name) { /* check whether func is a Lua function */ if (lua_tag(func) != LUA_T_PROTO) @@ -485,7 +482,7 @@ lua_Object lua_getlocal (lua_Function func, int local_number, char **name) } -int lua_setlocal (lua_Function func, int local_number) +int32 lua_setlocal (lua_Function func, int32 local_number) { /* check whether func is a Lua function */ if (lua_tag(func) != LUA_T_PROTO) @@ -508,7 +505,7 @@ int lua_setlocal (lua_Function func, int local_number) } -void lua_funcinfo (lua_Object func, const char **filename, int *linedefined) +void lua_funcinfo (lua_Object func, const char **filename, int32 *linedefined) { if (!lua_isfunction(func)) lua_error("API - `funcinfo' called with a non-function value"); @@ -526,7 +523,7 @@ void lua_funcinfo (lua_Object func, const char **filename, int *linedefined) } -static int checkfunc (TObject *o) +static int32 checkfunc (TObject *o) { return luaO_equalObj(o, L->stack.top); } @@ -566,9 +563,9 @@ void lua_endblock (void) -int lua_ref (int lock) +int32 lua_ref (int32 lock) { - int ref; + int32 ref; checkCparams(1); ref = luaC_ref(L->stack.top-1, lock); L->stack.top--; @@ -577,7 +574,7 @@ int lua_ref (int lock) -lua_Object lua_getref (int ref) +lua_Object lua_getref (int32 ref) { TObject *o = luaC_getref(ref); return (o ? put_luaObject(o) : LUA_NOOBJECT); @@ -589,11 +586,11 @@ lua_Object lua_getref (int ref) ** Derived functions ** ======================================================= */ -int (lua_call) (char *name) { return lua_call(name); } +int32 (lua_call) (char *name) { return lua_call(name); } -void (lua_pushref) (int ref) { lua_pushref(ref); } +void (lua_pushref) (int32 ref) { lua_pushref(ref); } -int (lua_refobject) (lua_Object o, int l) { return lua_refobject(o, l); } +int32 (lua_refobject) (lua_Object o, int32 l) { return lua_refobject(o, l); } void (lua_register) (char *n, lua_CFunction f) { lua_register(n, f); } @@ -601,7 +598,7 @@ void (lua_pushuserdata) (void *u) { lua_pushuserdata(u); } void (lua_pushcfunction) (lua_CFunction f) { lua_pushcfunction(f); } -int (lua_clonetag) (int t) { return lua_clonetag(t); } +int32 (lua_clonetag) (int32 t) { return lua_clonetag(t); } @@ -611,7 +608,7 @@ int (lua_clonetag) (int t) { return lua_clonetag(t); } ** API: set a function as a fallback */ -static void do_unprotectedrun (lua_CFunction f, int nParams, int nResults) +static void do_unprotectedrun (lua_CFunction f, int32 nParams, int32 nResults) { StkId base = (L->stack.top-L->stack.stack)-nParams; luaD_openstack(nParams); diff --git a/engine/lua/lapi.h b/engine/lua/lapi.h index d3d5a697737..f2af0fd7bd2 100644 --- a/engine/lua/lapi.h +++ b/engine/lua/lapi.h @@ -15,6 +15,6 @@ TObject *luaA_Address (lua_Object o); void luaA_pushobject (TObject *o); void luaA_packresults (void); -int luaA_passresults (void); +int32 luaA_passresults (void); #endif diff --git a/engine/lua/lauxlib.cpp b/engine/lua/lauxlib.cpp index 42066eec7d6..e0ab8f2195a 100644 --- a/engine/lua/lauxlib.cpp +++ b/engine/lua/lauxlib.cpp @@ -5,11 +5,6 @@ */ -#include -#include -#include -#include - /* Please Notice: This file uses only the official API of Lua ** Any function declared here could be written as an application ** function. With care, these functions can be used by other libraries. @@ -20,15 +15,15 @@ #include "lmem.h" -int luaL_findstring (const char *name, const char *list[]) { - int i; +int32 luaL_findstring (const char *name, const char *list[]) { + int32 i; for (i=0; list[i]; i++) if (strcmp(list[i], name) == 0) return i; return -1; /* name not found */ } -void luaL_argerror (int numarg, const char *extramsg) +void luaL_argerror (int32 numarg, const char *extramsg) { const char *funcname; lua_getobjname(lua_stackedfunction(0), &funcname); @@ -41,7 +36,7 @@ void luaL_argerror (int numarg, const char *extramsg) numarg, funcname, extramsg); } -const char *luaL_check_lstr (int numArg, long *len) +const char *luaL_check_lstr (int32 numArg, int32 *len) { lua_Object o = lua_getparam(numArg); luaL_arg_check(lua_isstring(o), numArg, "string expected"); @@ -49,13 +44,13 @@ const char *luaL_check_lstr (int numArg, long *len) return lua_getstring(o); } -const char *luaL_opt_lstr (int numArg, const char *def, long *len) +const char *luaL_opt_lstr (int32 numArg, const char *def, int32 *len) { return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : luaL_check_lstr(numArg, len); } -double luaL_check_number (int numArg) +double luaL_check_number (int32 numArg) { lua_Object o = lua_getparam(numArg); luaL_arg_check(lua_isnumber(o), numArg, "number expected"); @@ -63,28 +58,28 @@ double luaL_check_number (int numArg) } -double luaL_opt_number (int numArg, double def) +double luaL_opt_number (int32 numArg, double def) { return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : luaL_check_number(numArg); } -lua_Object luaL_tablearg (int arg) +lua_Object luaL_tablearg (int32 arg) { lua_Object o = lua_getparam(arg); luaL_arg_check(lua_istable(o), arg, "table expected"); return o; } -lua_Object luaL_functionarg (int arg) +lua_Object luaL_functionarg (int32 arg) { lua_Object o = lua_getparam(arg); luaL_arg_check(lua_isfunction(o), arg, "function expected"); return o; } -lua_Object luaL_nonnullarg (int numArg) +lua_Object luaL_nonnullarg (int32 numArg) { lua_Object o = lua_getparam(numArg); luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected"); @@ -93,7 +88,7 @@ lua_Object luaL_nonnullarg (int numArg) luaL_libList *list_of_libs = NULL; -void luaL_addlibtolist(luaL_reg *l, int n) { +void luaL_addlibtolist(luaL_reg *l, int32 n) { luaL_libList *list = (luaL_libList *)luaM_malloc(sizeof(luaL_libList)); list->list = l; list->number = n; @@ -110,9 +105,9 @@ void lua_removelibslists(void) { } } -void luaL_openlib (struct luaL_reg *l, int n) +void luaL_openlib (struct luaL_reg *l, int32 n) { - int i; + int32 i; lua_open(); /* make sure lua is already open */ for (i=0; i - #include "lauxlib.h" #include "lmem.h" #include "lstate.h" @@ -20,10 +18,10 @@ #define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size) -static void Openspace (int size) +static void Openspace (int32 size) { lua_State *l = L; /* to optimize */ - int base = l->Mbuffbase-l->Mbuffer; + int32 base = l->Mbuffbase-l->Mbuffer; l->Mbuffsize *= 2; if (l->Mbuffnext+size > l->Mbuffsize) /* still not big enough? */ l->Mbuffsize = l->Mbuffnext+size; @@ -32,14 +30,14 @@ static void Openspace (int size) } -char *luaL_openspace (int size) +char *luaL_openspace (int32 size) { openspace(size); return L->Mbuffer+L->Mbuffnext; } -void luaL_addchar (int c) +void luaL_addchar (int32 c) { openspace(BUFF_STEP); L->Mbuffer[L->Mbuffnext++] = c; @@ -52,26 +50,26 @@ void luaL_resetbuffer (void) } -void luaL_addsize (int n) +void luaL_addsize (int32 n) { L->Mbuffnext += n; } -int luaL_getsize (void) +int32 luaL_getsize (void) { return L->Mbuffnext-(L->Mbuffbase-L->Mbuffer); } -int luaL_newbuffer (int size) +int32 luaL_newbuffer (int32 size) { - int old = L->Mbuffbase-L->Mbuffer; + int32 old = L->Mbuffbase-L->Mbuffer; openspace(size); L->Mbuffbase = L->Mbuffer+L->Mbuffnext; return old; } -void luaL_oldbuffer (int old) +void luaL_oldbuffer (int32 old) { L->Mbuffnext = L->Mbuffbase-L->Mbuffer; L->Mbuffbase = L->Mbuffer+old; diff --git a/engine/lua/lbuiltin.cpp b/engine/lua/lbuiltin.cpp index b0a97707692..ed986622115 100644 --- a/engine/lua/lbuiltin.cpp +++ b/engine/lua/lbuiltin.cpp @@ -5,11 +5,6 @@ */ -#include -#include -#include -#include - #include "lapi.h" #include "lauxlib.h" #include "lbuiltin.h" @@ -100,7 +95,7 @@ static void foreach (void) { TObject t = *luaA_Address(luaL_tablearg(1)); TObject f = *luaA_Address(luaL_functionarg(2)); - int i; + int32 i; for (i=0; inhash; i++) { Node *nd = &(avalue(&t)->node[i]); if (ttype(ref(nd)) != LUA_T_NIL && ttype(val(nd)) != LUA_T_NIL) { @@ -118,7 +113,7 @@ static void foreach (void) static void internaldostring (void) { - long l; + int32 l; const char *s = luaL_check_lstr(1, &l); if (*s == ID_CHUNK) lua_error("`dostring' cannot run pre-compiled code"); @@ -185,7 +180,7 @@ static void to_string (void) { static void luaI_print (void) { TaggedString *ts = luaS_new("tostring"); lua_Object obj; - int i = 1; + int32 i = 1; while ((obj = lua_getparam(i++)) != LUA_NOOBJECT) { luaA_pushobject(&ts->u.s.globalval); lua_pushobject(obj); @@ -209,7 +204,7 @@ static void luaI_type (void) static void tonumber (void) { - int base = (int)luaL_opt_number(2, 10); + int32 base = (int32)luaL_opt_number(2, 10); if (base == 10) { /* standard conversion */ lua_Object o = lua_getparam(1); if (lua_isnumber(o)) @@ -217,10 +212,10 @@ static void tonumber (void) } else { const char *s = luaL_check_string(1); - char *e; - unsigned long n; + char *e; + int32 n; luaL_arg_check(0 <= base && base <= 36, 2, "base out of range"); - n = strtol(s, &e, base); + n = (int32)strtol(s, &e, base); while (isspace(*e)) e++; /* skip trailing spaces */ if (*e) lua_pushnil(); /* invalid format: return nil */ else lua_pushnumber(n); @@ -276,12 +271,12 @@ static void luatag (void) } -static int getnarg (lua_Object table) +static int32 getnarg (lua_Object table) { lua_Object temp; /* temp = table.n */ lua_pushobject(table); lua_pushstring("n"); temp = lua_rawgettable(); - return (lua_isnumber(temp) ? (int)lua_getnumber(temp) : MAX_INT); + return (lua_isnumber(temp) ? (int32)lua_getnumber(temp) : MAX_INT); } static void luaI_call (void) @@ -290,8 +285,8 @@ static void luaI_call (void) lua_Object arg = luaL_tablearg(2); const char *options = luaL_opt_string(3, ""); lua_Object err = lua_getparam(4); - int narg = getnarg(arg); - int i, status; + int32 narg = getnarg(arg); + int32 i, status; if (err != LUA_NOOBJECT) { /* set new error method */ lua_pushobject(err); err = lua_seterrormethod(); @@ -331,7 +326,7 @@ static void settag (void) { lua_Object o = luaL_tablearg(1); lua_pushobject(o); - lua_settag((int)luaL_check_number(2)); + lua_settag((int32)luaL_check_number(2)); lua_pushobject(o); /* returns first argument */ } @@ -344,8 +339,8 @@ static void newtag (void) static void copytagmethods (void) { - lua_pushnumber(lua_copytagmethods((int)luaL_check_number(1), - (int)luaL_check_number(2))); + lua_pushnumber(lua_copytagmethods((int32)luaL_check_number(1), + (int32)luaL_check_number(2))); } @@ -370,14 +365,14 @@ static void settagmethod (void) { lua_Object nf = luaL_nonnullarg(3); lua_pushobject(nf); - lua_pushobject(lua_settagmethod((int)luaL_check_number(1), + lua_pushobject(lua_settagmethod((int32)luaL_check_number(1), luaL_check_string(2))); } static void gettagmethod (void) { - lua_pushobject(lua_gettagmethod((int)luaL_check_number(1), + lua_pushobject(lua_gettagmethod((int32)luaL_check_number(1), luaL_check_string(2))); } @@ -392,7 +387,7 @@ static void seterrormethod (void) static void luaI_collectgarbage (void) { - lua_pushnumber(lua_collectgarbage((long int)luaL_opt_number(1, 0))); + lua_pushnumber(lua_collectgarbage((int32)luaL_opt_number(1, 0))); } @@ -415,7 +410,7 @@ static void countlist (void) char *s = luaL_check_string(1); GCnode *l = (s[0]=='t') ? L->roottable.next : (s[0]=='c') ? L->rootcl.next : (s[0]=='p') ? L->rootproto.next : L->rootglobal.next; - int i=0; + int32 i=0; while (l) { i++; l = l->next; @@ -429,7 +424,7 @@ static void testC (void) #define getnum(s) ((*s++) - '0') #define getname(s) (nome[0] = *s++, nome) - static int locks[10]; + static int32 locks[10]; lua_Object reg[10]; char nome[2]; char *s = luaL_check_string(1); @@ -447,16 +442,16 @@ static void testC (void) break; } case 'P': reg[getnum(s)] = lua_pop(); break; - case 'g': { int n=getnum(s); reg[n]=lua_getglobal(getname(s)); break; } - case 'G': { int n = getnum(s); + case 'g': { int32 n=getnum(s); reg[n]=lua_getglobal(getname(s)); break; } + case 'G': { int32 n = getnum(s); reg[n] = lua_rawgetglobal(getname(s)); break; } case 'l': locks[getnum(s)] = lua_ref(1); break; case 'L': locks[getnum(s)] = lua_ref(0); break; - case 'r': { int n=getnum(s); reg[n]=lua_getref(locks[getnum(s)]); break; } + case 'r': { int32 n=getnum(s); reg[n]=lua_getref(locks[getnum(s)]); break; } case 'u': lua_unref(locks[getnum(s)]); break; - case 'p': { int n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; } + case 'p': { int32 n = getnum(s); reg[n] = lua_getparam(getnum(s)); break; } case '=': lua_setglobal(getname(s)); break; case 's': lua_pushstring(getname(s)); break; case 'o': lua_pushobject(reg[getnum(s)]); break; diff --git a/engine/lua/ldo.cpp b/engine/lua/ldo.cpp index 1a41cc5830c..085faae4d8e 100644 --- a/engine/lua/ldo.cpp +++ b/engine/lua/ldo.cpp @@ -5,11 +5,6 @@ */ -#include -#include -#include -#include - #include "ldo.h" #include "lfunc.h" #include "lgc.h" @@ -74,12 +69,12 @@ void luaD_initthr (void) } -void luaD_checkstack (int n) +void luaD_checkstack (int32 n) { struct Stack *S = &L->stack; if (S->last-S->top <= n) { StkId top = S->top-S->stack; - int stacksize = (S->last-S->stack)+1+STACK_UNIT+n; + int32 stacksize = (S->last-S->stack)+1+STACK_UNIT+n; S->stack = luaM_reallocvector(S->stack, stacksize, TObject); S->last = S->stack+(stacksize-1); S->top = S->stack + top; @@ -98,7 +93,7 @@ void luaD_checkstack (int n) */ void luaD_adjusttop (StkId newtop) { - int diff = newtop-(L->stack.top-L->stack.stack); + int32 diff = newtop-(L->stack.top-L->stack.stack); if (diff <= 0) L->stack.top += diff; else { @@ -112,7 +107,7 @@ void luaD_adjusttop (StkId newtop) /* ** Open a hole below "nelems" from the L->stack.top. */ -void luaD_openstack (int nelems) +void luaD_openstack (int32 nelems) { luaO_memup(L->stack.top-nelems+1, L->stack.top-nelems, nelems*sizeof(TObject)); @@ -120,7 +115,7 @@ void luaD_openstack (int nelems) } -void luaD_lineHook (int line) +void luaD_lineHook (int32 line) { struct C_Lua_Stack oldCLS = L->Cstack; StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack; @@ -131,7 +126,7 @@ void luaD_lineHook (int line) } -void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn) +void luaD_callHook (StkId base, TProtoFunc *tf, int32 isreturn) { struct C_Lua_Stack oldCLS = L->Cstack; StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->stack.top-L->stack.stack; @@ -160,7 +155,7 @@ static StkId callC (lua_CFunction f, StkId base) struct C_Lua_Stack *CS = &L->Cstack; struct C_Lua_Stack oldCLS = *CS; StkId firstResult; - int numarg = (L->stack.top-L->stack.stack) - base; + int32 numarg = (L->stack.top-L->stack.stack) - base; CS->num = numarg; CS->lua2C = base; CS->base = base+numarg; /* == top-stack */ @@ -178,7 +173,7 @@ static StkId callC (lua_CFunction f, StkId base) static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base) { TObject *pbase; - int nup = cl->nelems; /* number of upvalues */ + int32 nup = cl->nelems; /* number of upvalues */ luaD_checkstack(nup); pbase = L->stack.stack+base; /* care: previous call may change this */ /* open space for upvalues as extra arguments */ @@ -190,7 +185,7 @@ static StkId callCclosure (struct Closure *cl, lua_CFunction f, StkId base) } -void luaD_callTM (TObject *f, int nParams, int nResults) +void luaD_callTM (TObject *f, int32 nParams, int32 nResults) { luaD_openstack(nParams); *(L->stack.top-nParams-1) = *f; @@ -211,13 +206,13 @@ static void adjust_varargs (StkId first_extra_arg) /* ** Prepare the stack for calling a Lua function. */ -void luaD_precall (TObject *f, StkId base, int nResults) +void luaD_precall (TObject *f, StkId base, int32 nResults) { /* Create a new CallInfo record */ if (L->ci+1 == L->end_ci) { - int size_ci = L->end_ci - L->base_ci; - int index_ci = L->ci - L->base_ci; - int new_ci_size = size_ci * 2 * sizeof(CallInfo); + int32 size_ci = L->end_ci - L->base_ci; + int32 index_ci = L->ci - L->base_ci; + int32 new_ci_size = size_ci * 2 * sizeof(CallInfo); CallInfo *new_ci = (CallInfo *)luaM_malloc(new_ci_size); memcpy(new_ci, L->base_ci, L->base_ci_size); memset(new_ci + (L->base_ci_size / sizeof(CallInfo)), 0, (new_ci_size) - L->base_ci_size); @@ -260,9 +255,9 @@ void luaD_precall (TObject *f, StkId base, int nResults) ** Adjust the stack to the desired number of results */ void luaD_postret (StkId firstResult) { - int i; + int32 i; StkId base = L->ci->base; - int nResults = L->ci->nResults; + int32 nResults = L->ci->nResults; if (L->ci == L->base_ci) lua_error("call stack underflow"); /* adjust the number of results */ @@ -284,7 +279,7 @@ void luaD_postret (StkId firstResult) { ** When returns, the results are on the L->stack.stack, between [L->stack.stack+base-1,L->stack.top). ** The number of results is nResults, unless nResults=MULT_RET. */ -void luaD_call (StkId base, int nResults) +void luaD_call (StkId base, int32 nResults) { StkId firstResult; TObject *func = L->stack.stack+base-1; @@ -322,7 +317,7 @@ void luaD_call (StkId base, int nResults) } -static void travstack (struct Stack *S, int (*fn)(TObject *)) { +static void travstack (struct Stack *S, int32 (*fn)(TObject *)) { StkId i; for (i = (S->top-1)-S->stack; i>=0; i--) fn(S->stack+i); @@ -331,7 +326,7 @@ static void travstack (struct Stack *S, int (*fn)(TObject *)) { /* ** Traverse all objects on L->stack.stack, and all other active stacks */ -void luaD_travstack (int (*fn)(TObject *)) +void luaD_travstack (int32 (*fn)(TObject *)) { struct lua_Task *t; travstack(&L->stack, fn); @@ -369,7 +364,7 @@ void lua_error (const char *s) ** Call the function at L->Cstack.base, and incorporate results on ** the Lua2C structure. */ -static void do_callinc (int nResults) +static void do_callinc (int32 nResults) { StkId base = L->Cstack.base; luaD_call(base+1, nResults); @@ -383,13 +378,13 @@ static void do_callinc (int nResults) ** Execute a protected call. Assumes that function is at L->Cstack.base and ** parameters are on top of it. Leave nResults on the stack. */ -int luaD_protectedrun (int nResults) +int32 luaD_protectedrun (int32 nResults) { jmp_buf myErrorJmp; - int status; + int32 status; struct C_Lua_Stack oldCLS = L->Cstack; jmp_buf *oldErr = L->errorJmp; - int ci_len = L->ci - L->base_ci; + int32 ci_len = L->ci - L->base_ci; L->errorJmp = &myErrorJmp; if (setjmp(myErrorJmp) == 0) { do_callinc(nResults); @@ -409,9 +404,9 @@ int luaD_protectedrun (int nResults) /* ** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load */ -static int protectedparser (ZIO *z, int bin) +static int32 protectedparser (ZIO *z, int32 bin) { - volatile int status; + volatile int32 status; TProtoFunc *volatile tf; jmp_buf myErrorJmp; jmp_buf *volatile oldErr = L->errorJmp; @@ -435,16 +430,16 @@ static int protectedparser (ZIO *z, int bin) } -static int do_main (ZIO *z, int bin) +static int32 do_main (ZIO *z, int32 bin) { - int status; + int32 status; do { - long old_blocks = (luaC_checkGC(), L->nblocks); + int32 old_blocks = (luaC_checkGC(), L->nblocks); status = protectedparser(z, bin); if (status == 1) return 1; /* error */ else if (status == 2) return 0; /* 'natural' end */ else { - unsigned long newelems2 = 2*(L->nblocks-old_blocks); + int32 newelems2 = 2*(L->nblocks-old_blocks); L->GCthreshold += newelems2; status = luaD_protectedrun(MULT_RET); L->GCthreshold -= newelems2; @@ -465,12 +460,12 @@ void luaD_gcIM (TObject *o) } -int lua_dofile (const char *filename) +int32 lua_dofile (const char *filename) { ZIO z; - int status; - int c; - int bin; + int32 status; + int32 c; + int32 bin; FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); if (f == NULL) return 2; @@ -508,15 +503,15 @@ static void build_name (const char *str, char *name) { } -int lua_dostring (const char *str) { +int32 lua_dostring (const char *str) { return lua_dobuffer(str, strlen(str), NULL); } -int lua_dobuffer (const char *buff, int size, const char *name) { +int32 lua_dobuffer (const char *buff, int32 size, const char *name) { char newname[SIZE_PREF+25]; ZIO z; - int status; + int32 status; if (name==NULL) { build_name(buff, newname); name = newname; diff --git a/engine/lua/ldo.h b/engine/lua/ldo.h index f06931ab6e7..6a6b04db116 100644 --- a/engine/lua/ldo.h +++ b/engine/lua/ldo.h @@ -33,17 +33,17 @@ void luaD_init (void); void luaD_initthr (void); void luaD_adjusttop (StkId newtop); -void luaD_openstack (int nelems); -void luaD_lineHook (int line); -void luaD_callHook (StkId base, TProtoFunc *tf, int isreturn); -void luaD_precall (TObject *f, StkId base, int nResults); +void luaD_openstack (int32 nelems); +void luaD_lineHook (int32 line); +void luaD_callHook (StkId base, TProtoFunc *tf, int32 isreturn); +void luaD_precall (TObject *f, StkId base, int32 nResults); void luaD_postret (StkId firstResult); -void luaD_call (StkId base, int nResults); -void luaD_callTM (TObject *f, int nParams, int nResults); -int luaD_protectedrun (int nResults); +void luaD_call (StkId base, int32 nResults); +void luaD_callTM (TObject *f, int32 nParams, int32 nResults); +int32 luaD_protectedrun (int32 nResults); void luaD_gcIM (TObject *o); -void luaD_travstack (int (*fn)(TObject *)); -void luaD_checkstack (int n); +void luaD_travstack (int32 (*fn)(TObject *)); +void luaD_checkstack (int32 n); #endif diff --git a/engine/lua/lfunc.cpp b/engine/lua/lfunc.cpp index a35779f7a8e..4f1662aa0c6 100644 --- a/engine/lua/lfunc.cpp +++ b/engine/lua/lfunc.cpp @@ -5,7 +5,6 @@ */ -#include #include "lfunc.h" #include "lmem.h" @@ -16,7 +15,7 @@ -Closure *luaF_newclosure (int nelems) +Closure *luaF_newclosure (int32 nelems) { Closure *c = (Closure *)luaM_malloc(sizeof(Closure)+nelems*sizeof(TObject)); luaO_insertlist(&(L->rootcl), (GCnode *)c); @@ -77,9 +76,9 @@ void luaF_freeclosure (Closure *l) ** Look for n-th local variable at line "line" in function "func". ** Returns NULL if not found. */ -char *luaF_getlocalname (TProtoFunc *func, int local_number, int line) +char *luaF_getlocalname (TProtoFunc *func, int32 local_number, int32 line) { - int count = 0; + int32 count = 0; char *varname = NULL; LocVar *lv = func->locvars; if (lv == NULL) diff --git a/engine/lua/lfunc.h b/engine/lua/lfunc.h index 6b94d760a6c..8cea4efd150 100644 --- a/engine/lua/lfunc.h +++ b/engine/lua/lfunc.h @@ -13,11 +13,11 @@ TProtoFunc *luaF_newproto (void); -Closure *luaF_newclosure (int nelems); +Closure *luaF_newclosure (int32 nelems); void luaF_freeproto (TProtoFunc *l); void luaF_freeclosure (Closure *l); -char *luaF_getlocalname (TProtoFunc *func, int local_number, int line); +char *luaF_getlocalname (TProtoFunc *func, int32 local_number, int32 line); #endif diff --git a/engine/lua/lgc.cpp b/engine/lua/lgc.cpp index 6b93616a656..f05b95235bb 100644 --- a/engine/lua/lgc.cpp +++ b/engine/lua/lgc.cpp @@ -18,7 +18,7 @@ -static int markobject (TObject *o); +static int32 markobject (TObject *o); @@ -29,9 +29,9 @@ static int markobject (TObject *o); */ -int luaC_ref (TObject *o, int lock) +int32 luaC_ref (TObject *o, int32 lock) { - int ref; + int32 ref; if (ttype(o) == LUA_T_NIL) ref = -1; /* special ref for nil */ else { @@ -39,7 +39,7 @@ int luaC_ref (TObject *o, int lock) if (L->refArray[ref].status == FREE) goto found; /* no more empty spaces */ { - int oldSize = L->refSize; + int32 oldSize = L->refSize; L->refSize = luaM_growvector(&L->refArray, L->refSize, struct ref, refEM, MAX_INT); for (ref=oldSize; refrefSize; ref++) @@ -53,14 +53,14 @@ int luaC_ref (TObject *o, int lock) } -void lua_unref (int ref) +void lua_unref (int32 ref) { if (ref >= 0 && ref < L->refSize) L->refArray[ref].status = FREE; } -TObject* luaC_getref (int ref) +TObject* luaC_getref (int32 ref) { if (ref == -1) return &luaO_nilobject; @@ -74,14 +74,14 @@ TObject* luaC_getref (int ref) static void travlock (void) { - int i; + int32 i; for (i=0; irefSize; i++) if (L->refArray[i].status == LOCK) markobject(&L->refArray[i].o); } -static int ismarked (TObject *o) +static int32 ismarked (TObject *o) { /* valid only for locked objects */ switch (o->ttype) { @@ -106,7 +106,7 @@ static int ismarked (TObject *o) static void invalidaterefs (void) { - int i; + int32 i; for (i=0; irefSize; i++) if (L->refArray[i].status == HOLD && !ismarked(&L->refArray[i].o)) L->refArray[i].status = COLLECTED; @@ -167,7 +167,7 @@ static void protomark (TProtoFunc *f) { if (!f->head.marked) { LocVar *v = f->locvars; - int i; + int32 i; f->head.marked = 1; if (f->fileName) strmark(f->fileName); @@ -185,7 +185,7 @@ static void protomark (TProtoFunc *f) static void closuremark (Closure *f) { if (!f->head.marked) { - int i; + int32 i; f->head.marked = 1; for (i=f->nelems; i>=0; i--) markobject(&f->consts[i]); @@ -196,7 +196,7 @@ static void closuremark (Closure *f) static void hashmark (Hash *h) { if (!h->head.marked) { - int i; + int32 i; h->head.marked = 1; for (i=0; inblocks; /* to subtract nblocks after gc */ + int32 recovered = L->nblocks; /* to subtract nblocks after gc */ Hash *freetable; TaggedString *freestr; TProtoFunc *freefunc; diff --git a/engine/lua/lgc.h b/engine/lua/lgc.h index 7ed687ade02..6bb4bc7cde0 100644 --- a/engine/lua/lgc.h +++ b/engine/lua/lgc.h @@ -12,8 +12,8 @@ void luaC_checkGC (void); -TObject* luaC_getref (int ref); -int luaC_ref (TObject *o, int lock); +TObject* luaC_getref (int32 ref); +int luaC_ref (TObject *o, int32 lock); void luaC_hashcallIM (Hash *l); void luaC_strcallIM (TaggedString *l); diff --git a/engine/lua/liolib.cpp b/engine/lua/liolib.cpp index 1e32f323bf9..1256d589de1 100644 --- a/engine/lua/liolib.cpp +++ b/engine/lua/liolib.cpp @@ -5,35 +5,17 @@ */ -#include -#include -#include -#include -#include - #include "lauxlib.h" #include "lua.h" #include "luadebug.h" #include "lualib.h" +#include + #ifdef LUA_ADD_CUSTOM_FOPEN #include "../resource.h" #endif -#ifndef OLD_ANSI -#include -#else -#define setlocale(a,b) 0 -#define LC_ALL 0 -#define LC_COLLATE 0 -#define LC_CTYPE 0 -#define LC_MONETARY 0 -#define LC_NUMERIC 0 -#define LC_TIME 0 -#define strerror(e) "(no error message provided by operating system)" -#endif - - #define CLOSEDTAG 2 #define IOTAG 1 @@ -43,21 +25,16 @@ #define FOUTPUT "_OUTPUT" -#ifdef POPEN -FILE *popen(); -int pclose(); -#else #define popen(x,y) NULL /* that is, popen always fails */ #define pclose(x) (-1) -#endif -static int gettag (int i) +static int32 gettag (int32 i) { - return (int)lua_getnumber(lua_getparam(i)); + return (int32)lua_getnumber(lua_getparam(i)); } -static void pushresult (int i) +static void pushresult (int32 i) { if (i) lua_pushuserdata(NULL); @@ -68,7 +45,7 @@ static void pushresult (int i) } -static int ishandler (lua_Object f) +static int32 ishandler (lua_Object f) { if (lua_isuserdata(f)) { if (lua_tag(f) == gettag(CLOSEDTAG)) @@ -87,7 +64,7 @@ static FILE *getfile (const char *name) } -static FILE *getfileparam (const char *name, int *arg) +static FILE *getfileparam (const char *name, int32 *arg) { lua_Object f = lua_getparam(*arg); if (ishandler(f)) { @@ -110,7 +87,7 @@ static void closefile (const char *name) } -static void setfile (FILE *f, const char *name, int tag) +static void setfile (FILE *f, const char *name, int32 tag) { lua_pushusertag(f, tag); lua_setglobal(name); @@ -119,7 +96,7 @@ static void setfile (FILE *f, const char *name, int tag) static void setreturn (FILE *f, const char *name) { - int tag = gettag(IOTAG); + int32 tag = gettag(IOTAG); setfile(f, name, tag); lua_pushusertag(f, tag); } @@ -191,9 +168,9 @@ static void io_appendto (void) #define NEED_OTHER (EOF-1) /* just some flag different from EOF */ -static void read_until (FILE *f, int lim) { - int l = 0; - int c; +static void read_until (FILE *f, int32 lim) { + int32 l = 0; + int32 c; for (c = getc(f); c != EOF && c != lim; c = getc(f)) { luaL_addchar(c); l++; @@ -203,7 +180,7 @@ static void read_until (FILE *f, int lim) { } static void io_read (void) { - int arg = FIRSTARG; + int32 arg = FIRSTARG; FILE *f = getfileparam(FINPUT, &arg); const char *p = luaL_opt_string(arg, NULL); luaL_resetbuffer(); @@ -212,9 +189,9 @@ static void io_read (void) { else if (p[0] == '.' && p[1] == '*' && p[2] == 0) /* p = ".*" */ read_until(f, EOF); else { - int l = 0; /* number of chars read in buffer */ - int inskip = 0; /* to control {skips} */ - int c = NEED_OTHER; + int32 l = 0; /* number of chars read in buffer */ + int32 inskip = 0; /* to control {skips} */ + int32 c = NEED_OTHER; while (*p) { switch (*p) { case '{': @@ -229,7 +206,7 @@ static void io_read (void) { continue; default: { const char *ep; /* get what is next */ - int m; /* match result */ + int32 m; /* match result */ if (c == NEED_OTHER) c = getc(f); if (c == EOF) { luaI_singlematch(0, p, &ep); /* to set "ep" */ @@ -270,13 +247,13 @@ static void io_read (void) { static void io_write (void) { - int arg = FIRSTARG; + int32 arg = FIRSTARG; FILE *f = getfileparam(FOUTPUT, &arg); - int status = 1; + int32 status = 1; const char *s; - long l; + int32 l; while ((s = luaL_opt_lstr(arg++, NULL, &l)) != NULL) - status = status && (fwrite(s, 1, l, f) == (unsigned long)l); + status = status && (fwrite(s, 1, l, f) == (size_t)l); pushresult(status); } @@ -334,11 +311,11 @@ static void io_date (void) static void setloc (void) { - static int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, + static int32 cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME}; static const char *catnames[] = {"all", "collate", "ctype", "monetary", "numeric", "time", NULL}; - int op = luaL_findstring(luaL_opt_string(2, "all"), catnames); + int32 op = luaL_findstring(luaL_opt_string(2, "all"), catnames); luaL_arg_check(op != -1, 2, "invalid option"); lua_pushstring(setlocale(cat[op], luaL_check_string(1))); } @@ -347,7 +324,7 @@ static void setloc (void) static void io_exit (void) { lua_Object o = lua_getparam(1); - exit(lua_isnumber(o) ? (int)lua_getnumber(o) : 1); + exit((int)lua_isnumber(o) ? (int)lua_getnumber(o) : 1); } @@ -365,13 +342,13 @@ static void io_debug (void) static void lua_printstack (FILE *f) { - int level = 1; /* skip level 0 (it's this function) */ + int32 level = 1; /* skip level 0 (it's this function) */ lua_Object func; while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) { const char *name; - int currentline; + int32 currentline; const char *filename; - int linedefined; + int32 linedefined; lua_funcinfo(func, &filename, &linedefined); fprintf(f, (level==2) ? "Active Stack:\n\t" : "\t"); switch (*lua_getobjname(func, &name)) { @@ -432,9 +409,9 @@ static struct luaL_reg iolibtag[] = { static void openwithtags (void) { - int iotag = lua_newtag(); - int closedtag = lua_newtag(); - unsigned int i; + int32 iotag = lua_newtag(); + int32 closedtag = lua_newtag(); + int32 i; for (i=0; i -#include - #include "lauxlib.h" #include "llex.h" #include "lmem.h" @@ -20,7 +17,7 @@ -int lua_debug=0; +int32 lua_debug=0; #define next(LS) (LS->current = zgetc(LS->lex_z)) @@ -37,7 +34,7 @@ const char *reserved [] = {"and", "do", "else", "elseif", "end", "function", void luaX_init (void) { - unsigned int i; + int32 i; for (i=0; i<(sizeof(reserved)/sizeof(reserved[0])); i++) { TaggedString *ts = luaS_new(reserved[i]); ts->head.marked = FIRST_RESERVED+i; /* reserved word (always > 255) */ @@ -59,7 +56,7 @@ void luaX_error (LexState *ls, const char *s) { } -void luaX_token2str (LexState * /*ls*/, int token, char *s) { +void luaX_token2str (LexState * /*ls*/, int32 token, char *s) { if (token < 255) { s[0] = token; s[1] = 0; @@ -69,7 +66,7 @@ void luaX_token2str (LexState * /*ls*/, int token, char *s) { } -static void luaX_invalidchar (LexState *ls, int c) { +static void luaX_invalidchar (LexState *ls, int32 c) { char buff[10]; sprintf(buff, "0x%X", c); luaX_syntaxerror(ls, "invalid control char", buff); @@ -78,7 +75,7 @@ static void luaX_invalidchar (LexState *ls, int c) { static void firstline (LexState *LS) { - int c = zgetc(LS->lex_z); + int32 c = zgetc(LS->lex_z); if (c == '#') while ((c=zgetc(LS->lex_z)) != '\n' && c != EOZ) /* skip first line */; zungetc(LS->lex_z); @@ -115,12 +112,12 @@ static void skipspace (LexState *LS) } -static int checkcond (LexState *LS, char *buff) +static int32 checkcond (LexState *LS, char *buff) { static const char *opts[] = {"nil", "1", NULL}; - int i = luaL_findstring(buff, opts); + int32 i = luaL_findstring(buff, opts); if (i >= 0) return i; - else if (isalpha((unsigned char)buff[0]) || buff[0] == '_') + else if (isalpha((byte)buff[0]) || buff[0] == '_') return luaS_globaldefined(buff); else { luaX_syntaxerror(LS, "invalid $if condition", buff); @@ -131,7 +128,7 @@ static int checkcond (LexState *LS, char *buff) static void readname (LexState *LS, char *buff) { - int i = 0; + int32 i = 0; skipspace(LS); while (isalnum(LS->current) || LS->current == '_') { if (i >= PRAGMASIZE) { @@ -168,8 +165,8 @@ static void inclinenumber (LexState *LS) ++LS->linenumber; if (LS->current == '$') { /* is a pragma? */ char buff[PRAGMASIZE+1]; - int ifnot = 0; - int skip = LS->ifstate[LS->iflevel].skip; + int32 ifnot = 0; + int32 skip = LS->ifstate[LS->iflevel].skip; next(LS); /* skip $ */ readname(LS, buff); switch (luaL_findstring(buff, pragmas)) { @@ -231,9 +228,9 @@ static void inclinenumber (LexState *LS) -static int read_long_string (LexState *LS) +static int32 read_long_string (LexState *LS) { - int cont = 0; + int32 cont = 0; while (1) { switch (LS->current) { case EOZ: @@ -269,7 +266,7 @@ static int read_long_string (LexState *LS) } -int luaX_lex (LexState *LS) { +int32 luaX_lex (LexState *LS) { double a; luaL_resetbuffer(); while (1) { @@ -320,7 +317,7 @@ int luaX_lex (LexState *LS) { case '"': case '\'': { - int del = LS->current; + int32 del = LS->current; save_and_next(LS); while (LS->current != del) { switch (LS->current) { @@ -341,8 +338,8 @@ int luaX_lex (LexState *LS) { case '\n': save('\n'); inclinenumber(LS); break; default : { if (isdigit(LS->current)) { - int c = 0; - int i = 0; + int32 c = 0; + int32 i = 0; do { c = 10*c + (LS->current-'0'); next(LS); @@ -410,8 +407,8 @@ int luaX_lex (LexState *LS) { save_and_next(LS); } if (toupper(LS->current) == 'E') { - int e = 0; - int neg; + int32 e = 0; + int32 neg; double ea; save_and_next(LS); neg = (LS->current=='-'); @@ -439,7 +436,7 @@ int luaX_lex (LexState *LS) { default: if (LS->current != '_' && !isalpha(LS->current)) { - int c = LS->current; + int32 c = LS->current; if (iscntrl(c)) luaX_invalidchar(LS, c); save_and_next(LS); diff --git a/engine/lua/llex.h b/engine/lua/llex.h index 0e2accf73ef..326e7b279e0 100644 --- a/engine/lua/llex.h +++ b/engine/lua/llex.h @@ -30,33 +30,33 @@ enum RESERVED { /* "ifstate" keeps the state of each nested $if the lexical is dealing with. */ struct ifState { - int elsepart; /* true if its in the $else part */ - int condition; /* true if $if condition is true */ - int skip; /* true if part must be skipped */ + int32 elsepart; /* true if its in the $else part */ + int32 condition; /* true if $if condition is true */ + int32 skip; /* true if part must be skipped */ }; typedef struct LexState { - int current; /* look ahead character */ - int token; /* look ahead token */ + int32 current; /* look ahead character */ + int32 token; /* look ahead token */ struct FuncState *fs; /* 'FuncState' is private for the parser */ union { real r; TaggedString *ts; } seminfo; /* semantics information */ struct zio *lex_z; /* input stream */ - int linenumber; /* input line counter */ - int iflevel; /* level of nested $if's (for lexical analysis) */ + int32 linenumber; /* input line counter */ + int32 iflevel; /* level of nested $if's (for lexical analysis) */ struct ifState ifstate[MAX_IFS]; } LexState; void luaX_init (void); void luaX_setinput (LexState *LS, ZIO *z); -int luaX_lex (LexState *LS); +int32 luaX_lex (LexState *LS); void luaX_syntaxerror (LexState *ls, const char *s, const char *token); void luaX_error (LexState *ls, const char *s); -void luaX_token2str (LexState *ls, int token, char *s); +void luaX_token2str (LexState *ls, int32 token, char *s); #endif diff --git a/engine/lua/lmathlib.cpp b/engine/lua/lmathlib.cpp index f56590a24ea..5a41a73656f 100644 --- a/engine/lua/lmathlib.cpp +++ b/engine/lua/lmathlib.cpp @@ -5,9 +5,6 @@ */ -#include -#include - #include "lauxlib.h" #include "lua.h" #include "lualib.h" @@ -114,20 +111,20 @@ static void math_rad (void) } static void math_frexp (void) { - int e; + int32 e; lua_pushnumber(frexp(luaL_check_number(1), &e)); lua_pushnumber(e); } static void math_ldexp (void) { - lua_pushnumber(ldexp(luaL_check_number(1), (int)luaL_check_number(2))); + lua_pushnumber(ldexp(luaL_check_number(1), (int32)luaL_check_number(2))); } static void math_min (void) { - int i = 1; + int32 i = 1; double dmin = luaL_check_number(i); while (lua_getparam(++i) != LUA_NOOBJECT) { double d = luaL_check_number(i); @@ -140,7 +137,7 @@ static void math_min (void) static void math_max (void) { - int i = 1; + int32 i = 1; double dmax = luaL_check_number(i); while (lua_getparam(++i) != LUA_NOOBJECT) { double d = luaL_check_number(i); @@ -160,7 +157,7 @@ static void math_random (void) if (l == 0) lua_pushnumber(r); else - lua_pushnumber((int)(r*l)+1); + lua_pushnumber((int32)(r*l)+1); } diff --git a/engine/lua/lmem.cpp b/engine/lua/lmem.cpp index 88e48c86619..e20b3ff47af 100644 --- a/engine/lua/lmem.cpp +++ b/engine/lua/lmem.cpp @@ -5,7 +5,6 @@ */ -#include #include "lmem.h" #include "lstate.h" @@ -13,8 +12,8 @@ -int luaM_growaux (void **block, unsigned long nelems, int size, - const char *errormsg, unsigned long limit) +int32 luaM_growaux (void **block, int32 nelems, int32 size, + const char *errormsg, int32 limit) { if (nelems >= limit) lua_error(errormsg); @@ -22,7 +21,7 @@ int luaM_growaux (void **block, unsigned long nelems, int size, if (nelems > limit) nelems = limit; *block = luaM_realloc(*block, nelems*size); - return (int)nelems; + return (int32)nelems; } @@ -35,7 +34,7 @@ int luaM_growaux (void **block, unsigned long nelems, int size, ** since realloc(NULL, s)==malloc(s) and realloc(b, 0)==free(b). ** But some systems (e.g. Sun OS) are not that ANSI... */ -void *luaM_realloc (void *block, unsigned long size) +void *luaM_realloc (void *block, int32 size) { size_t s = (size_t)size; if (s != size) @@ -64,14 +63,14 @@ void *luaM_realloc (void *block, unsigned long size) #define MARK 55 -unsigned long numblocks = 0; -unsigned long totalmem = 0; +int32 numblocks = 0; +int32 totalmem = 0; static void *checkblock (void *block) { - unsigned long *b = (unsigned long *)((char *)block - HEADER); - unsigned long size = *b; + int32 *b = (uint32 *)((char *)block - HEADER); + int32 size = *b; LUA_ASSERT(*(((char *)b)+size+HEADER) == MARK, "corrupted block"); numblocks--; @@ -80,14 +79,14 @@ static void *checkblock (void *block) } -void *luaM_realloc (void *block, unsigned long size) +void *luaM_realloc (void *block, int32 size) { - unsigned long realsize = HEADER+size+1; + int32 realsize = HEADER+size+1; if (realsize != (size_t)realsize) lua_error("Allocation Error: Block too big"); if (size == 0) { /* ANSI dosen't need this, but some machines... */ if (block) { - unsigned long *b = (unsigned long *)((char *)block - HEADER); + int32 *b = (int32 *)((char *)block - HEADER); memset(block, -1, *b); /* erase block */ block = checkblock(block); free(block); @@ -96,17 +95,17 @@ void *luaM_realloc (void *block, unsigned long size) } if (block) { block = checkblock(block); - block = (unsigned long *)realloc(block, realsize); + block = (int32 *)realloc(block, realsize); } else - block = (unsigned long *)malloc(realsize); + block = (int32 *)malloc(realsize); if (block == NULL) lua_error(memEM); totalmem += size; numblocks++; - *(unsigned long *)block = size; + *(int32 *)block = size; *(((char *)block)+size+HEADER) = MARK; - return (unsigned long *)((char *)block+HEADER); + return (int32 *)((char *)block+HEADER); } diff --git a/engine/lua/lmem.h b/engine/lua/lmem.h index c957bfcbf18..8ae3448cb37 100644 --- a/engine/lua/lmem.h +++ b/engine/lua/lmem.h @@ -7,6 +7,8 @@ #ifndef lmem_h #define lmem_h +#include "common\sys.h" + #ifndef NULL #define NULL 0 @@ -20,9 +22,9 @@ #define tableEM "table overflow" #define memEM "not enough memory" -void *luaM_realloc (void *oldblock, unsigned long size); -int luaM_growaux (void **block, unsigned long nelems, int size, - const char *errormsg, unsigned long limit); +void *luaM_realloc (void *oldblock, int32 size); +int32 luaM_growaux (void **block, int32 nelems, int32 size, + const char *errormsg, int32 limit); #define luaM_free(b) free((b)) #define luaM_malloc(t) malloc((t)) @@ -34,8 +36,8 @@ int luaM_growaux (void **block, unsigned long nelems, int size, #ifdef DEBUG -extern unsigned long numblocks; -extern unsigned long totalmem; +extern int32 numblocks; +extern int32 totalmem; #endif diff --git a/engine/lua/lobject.cpp b/engine/lua/lobject.cpp index 92ed92f56a5..51544b24f29 100644 --- a/engine/lua/lobject.cpp +++ b/engine/lua/lobject.cpp @@ -21,15 +21,15 @@ TObject luaO_nilobject = {LUA_T_NIL, {NULL}}; /* hash dimensions values */ -static long dimensions[] = - {5L, 11L, 23L, 47L, 97L, 197L, 397L, 797L, 1597L, 3203L, 6421L, - 12853L, 25717L, 51437L, 102811L, 205619L, 411233L, 822433L, - 1644817L, 3289613L, 6579211L, 13158023L, MAX_INT}; +static int32 dimensions[] = + {5, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, + 12853, 25717, 51437, 102811, 205619, 411233, 822433, + 1644817, 3289613, 6579211, 13158023, MAX_INT}; -int luaO_redimension (int oldsize) +int32 luaO_redimension (int32 oldsize) { - int i; + int32 i; for (i=0; dimensions[i] oldsize) return dimensions[i]; @@ -39,7 +39,7 @@ int luaO_redimension (int oldsize) } -int luaO_equalObj (TObject *t1, TObject *t2) +int32 luaO_equalObj (TObject *t1, TObject *t2) { if (ttype(t1) != ttype(t2)) return 0; switch (ttype(t1)) { @@ -64,21 +64,3 @@ void luaO_insertlist (GCnode *root, GCnode *node) root->next = node; node->marked = 0; } - -#ifdef OLD_ANSI -void luaO_memup (void *dest, void *src, int size) -{ - char *d = dest; - char *s = src; - while (size--) d[size]=s[size]; -} - -void luaO_memdown (void *dest, void *src, int size) -{ - char *d = dest; - char *s = src; - int i; - for (i=0; i - #include "lua.h" @@ -40,17 +38,11 @@ typedef LUA_NUM_TYPE real; #define Byte lua_Byte /* some systems have Byte as a predefined type */ -typedef unsigned char Byte; /* unsigned 8 bits */ +typedef byte Byte; /* unsigned 8 bits */ -#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ - -/* maximum value of a word of 2 bytes (-2 for safety); must fit in an "int" */ -#if MAX_INT < 65534 -#define MAX_WORD MAX_INT -#else -#define MAX_WORD 65534 -#endif +#define MAX_INT (2147483647-2) /* maximum value of an int (-2 for safety) */ +#define MAX_WORD 65534 typedef unsigned long IntPoint; /* unsigned with same size as a pointer (for hashing) */ @@ -87,7 +79,7 @@ typedef union { struct TProtoFunc *tf; /* LUA_T_PROTO, LUA_T_PMARK */ struct Closure *cl; /* LUA_T_CLOSURE, LUA_T_CLMARK */ struct Hash *a; /* LUA_T_ARRAY */ - int i; /* LUA_T_LINE */ + int32 i; /* LUA_T_LINE */ } Value; @@ -103,7 +95,7 @@ typedef struct TObject { */ typedef struct GCnode { struct GCnode *next; - int marked; + int32 marked; } GCnode; @@ -114,14 +106,14 @@ typedef struct GCnode { typedef struct TaggedString { GCnode head; unsigned long hash; - int constindex; /* hint to reuse constants (= -1 if this is a userdata) */ + int32 constindex; /* hint to reuse constants (= -1 if this is a userdata) */ union { struct { TObject globalval; - long len; /* if this is a string, here is its length */ + int32 len; /* if this is a string, here is its length */ } s; struct { - int tag; + int32 tag; void *v; /* if this is a userdata, here is its value */ } d; } u; @@ -137,16 +129,16 @@ typedef struct TaggedString { typedef struct TProtoFunc { GCnode head; struct TObject *consts; - int nconsts; + int32 nconsts; Byte *code; /* ends with opcode ENDCODE */ - int lineDefined; + int32 lineDefined; TaggedString *fileName; struct LocVar *locvars; /* ends with line = -1 */ } TProtoFunc; typedef struct LocVar { TaggedString *varname; /* NULL signals end of scope */ - int line; + int32 line; } LocVar; @@ -171,7 +163,7 @@ typedef struct LocVar { */ typedef struct Closure { GCnode head; - int nelems; /* not included the first one (always the prototype) */ + int32 nelems; /* not included the first one (always the prototype) */ TObject consts[1]; /* at least one for prototype */ } Closure; @@ -185,9 +177,9 @@ typedef struct node { typedef struct Hash { GCnode head; Node *node; - int nhash; - int nuse; - int htag; + int32 nhash; + int32 nuse; + int32 htag; } Hash; @@ -195,17 +187,11 @@ extern const char *luaO_typenames[]; extern TObject luaO_nilobject; -int luaO_equalObj (TObject *t1, TObject *t2); -int luaO_redimension (int oldsize); +int32 luaO_equalObj (TObject *t1, TObject *t2); +int32 luaO_redimension (int32 oldsize); void luaO_insertlist (GCnode *root, GCnode *node); -#ifdef OLD_ANSI -void luaO_memup (void *dest, void *src, int size); -void luaO_memdown (void *dest, void *src, int size); -#else -#include #define luaO_memup(d,s,n) memmove(d,s,n) #define luaO_memdown(d,s,n) memmove(d,s,n) -#endif #endif diff --git a/engine/lua/lparser.cpp b/engine/lua/lparser.cpp index 7c2191d91a9..ced6642f3db 100644 --- a/engine/lua/lparser.cpp +++ b/engine/lua/lparser.cpp @@ -5,9 +5,6 @@ */ -#include -#include - #include "lauxlib.h" #include "ldo.h" #include "lfunc.h" @@ -52,7 +49,7 @@ typedef enum {VGLOBAL, VLOCAL, VDOT, VINDEXED, VEXP} varkind; typedef struct { varkind k; - int info; + int32 info; } vardesc; @@ -63,8 +60,8 @@ typedef struct { ** where is its pc index of "nparam" */ typedef struct { - int n; - int pc; /* 0 if last expression is closed */ + int32 n; + int32 pc; /* 0 if last expression is closed */ } listdesc; @@ -75,8 +72,8 @@ typedef struct { ** or empty (k = ';' or '}') */ typedef struct { - int n; - int k; + int32 n; + int32 k; } constdesc; @@ -84,32 +81,32 @@ typedef struct { typedef struct FuncState { TProtoFunc *f; /* current function header */ struct FuncState *prev; /* enclosuring function */ - int pc; /* next position to code */ - int stacksize; /* number of values on activation register */ - int maxstacksize; /* maximum number of values on activation register */ - int nlocalvar; /* number of active local variables */ - int nupvalues; /* number of upvalues */ - int nvars; /* number of entries in f->locvars */ - int maxcode; /* size of f->code */ - int maxvars; /* size of f->locvars (-1 if no debug information) */ - int maxconsts; /* size of f->consts */ - int lastsetline; /* line where last SETLINE was issued */ + int32 pc; /* next position to code */ + int32 stacksize; /* number of values on activation register */ + int32 maxstacksize; /* maximum number of values on activation register */ + int32 nlocalvar; /* number of active local variables */ + int32 nupvalues; /* number of upvalues */ + int32 nvars; /* number of entries in f->locvars */ + int32 maxcode; /* size of f->code */ + int32 maxvars; /* size of f->locvars (-1 if no debug information) */ + int32 maxconsts; /* size of f->consts */ + int32 lastsetline; /* line where last SETLINE was issued */ vardesc upvalues[MAXUPVALUES]; /* upvalues */ TaggedString *localvar[MAXLOCALS]; /* store local variable names */ } FuncState; -static int assignment (LexState *ls, vardesc *v, int nvars); -static int cond (LexState *ls); -static int funcname (LexState *ls, vardesc *v); -static int funcparams (LexState *ls, int slf); -static int listfields (LexState *ls); -static int localnamelist (LexState *ls); -static int optional (LexState *ls, int c); -static int recfields (LexState *ls); -static int stat (LexState *ls); +static int32 assignment (LexState *ls, vardesc *v, int32 nvars); +static int32 cond (LexState *ls); +static int32 funcname (LexState *ls, vardesc *v); +static int32 funcparams (LexState *ls, int32 slf); +static int32 listfields (LexState *ls); +static int32 localnamelist (LexState *ls); +static int32 optional (LexState *ls, int32 c); +static int32 recfields (LexState *ls); +static int32 stat (LexState *ls); static void block (LexState *ls); -static void body (LexState *ls, int needself, int line); +static void body (LexState *ls, int32 needself, int32 line); static void chunk (LexState *ls); static void constructor (LexState *ls); static void decinit (LexState *ls, listdesc *d); @@ -130,7 +127,7 @@ static void var_or_func_tail (LexState *ls, vardesc *v); -static void check_pc (FuncState *fs, int n) { +static void check_pc (FuncState *fs, int32 n) { if (fs->pc+n > fs->maxcode) fs->maxcode = luaM_growvector(&fs->f->code, fs->maxcode, Byte, codeEM, MAX_INT); @@ -143,7 +140,7 @@ static void code_byte (FuncState *fs, Byte c) { } -static void deltastack (LexState *ls, int delta) { +static void deltastack (LexState *ls, int32 delta) { FuncState *fs = ls->fs; fs->stacksize += delta; if (fs->stacksize > fs->maxstacksize) { @@ -154,8 +151,8 @@ static void deltastack (LexState *ls, int delta) { } -static int code_oparg_at (LexState *ls, int pc, OpCode op, int builtin, - int arg, int delta) { +static int32 code_oparg_at (LexState *ls, int32 pc, OpCode op, int32 builtin, + int32 arg, int32 delta) { Byte *code = ls->fs->f->code; deltastack(ls, delta); if (arg < builtin) { @@ -178,7 +175,7 @@ static int code_oparg_at (LexState *ls, int pc, OpCode op, int builtin, } -static int fix_opcode (LexState *ls, int pc, OpCode op, int builtin, int arg) { +static int32 fix_opcode (LexState *ls, int32 pc, OpCode op, int32 builtin, int32 arg) { FuncState *fs = ls->fs; TProtoFunc *f = fs->f; if (arg < builtin) { /* close space */ @@ -193,25 +190,25 @@ static int fix_opcode (LexState *ls, int pc, OpCode op, int builtin, int arg) { return code_oparg_at(ls, pc, op, builtin, arg, 0) - 2; } -static void code_oparg (LexState *ls, OpCode op, int builtin, int arg, - int delta) { +static void code_oparg (LexState *ls, OpCode op, int32 builtin, int32 arg, + int32 delta) { check_pc(ls->fs, 3); /* maximum code size */ ls->fs->pc += code_oparg_at(ls, ls->fs->pc, op, builtin, arg, delta); } -static void code_opcode (LexState *ls, OpCode op, int delta) { +static void code_opcode (LexState *ls, OpCode op, int32 delta) { deltastack(ls, delta); code_byte(ls->fs, op); } -static void code_constant (LexState *ls, int c) { +static void code_constant (LexState *ls, int32 c) { code_oparg(ls, PUSHCONSTANT, 8, c, 1); } -static int next_constant (FuncState *fs) { +static int32 next_constant (FuncState *fs) { TProtoFunc *f = fs->f; if (f->nconsts >= fs->maxconsts) { fs->maxconsts = luaM_growvector(&f->consts, fs->maxconsts, TObject, @@ -221,9 +218,9 @@ static int next_constant (FuncState *fs) { } -static int string_constant (FuncState *fs, TaggedString *s) { +static int32 string_constant (FuncState *fs, TaggedString *s) { TProtoFunc *f = fs->f; - int c = s->constindex; + int32 c = s->constindex; if (!(c < f->nconsts && ttype(&f->consts[c]) == LUA_T_STRING && tsvalue(&f->consts[c]) == s)) { c = next_constant(fs); @@ -241,11 +238,11 @@ static void code_string (LexState *ls, TaggedString *s) { #define LIM 20 -static int real_constant (FuncState *fs, real r) { +static int32 real_constant (FuncState *fs, real r) { /* check whether 'r' has appeared within the last LIM entries */ TObject *cnt = fs->f->consts; - int c = fs->f->nconsts; - int lim = c < LIM ? 0 : c-LIM; + int32 c = fs->f->nconsts; + int32 lim = c < LIM ? 0 : c-LIM; while (--c >= lim) { if (ttype(&cnt[c]) == LUA_T_NUMBER && nvalue(&cnt[c]) == r) return c; @@ -260,21 +257,21 @@ static int real_constant (FuncState *fs, real r) { static void code_number (LexState *ls, real f) { - int i; - if (f >= 0 && f <= (real)MAX_WORD && (real)(i=(int)f) == f) + int32 i; + if (f >= 0 && f <= (real)MAX_WORD && (real)(i=(int32)f) == f) code_oparg(ls, PUSHNUMBER, 3, i, 1); /* f has a short integer value */ else code_constant(ls, real_constant(ls->fs, f)); } -static void flush_record (LexState *ls, int n) { +static void flush_record (LexState *ls, int32 n) { if (n > 0) code_oparg(ls, SETMAP, 1, n-1, -2*n); } -static void flush_list (LexState *ls, int m, int n) { +static void flush_list (LexState *ls, int32 m, int32 n) { if (n == 0) return; code_oparg(ls, SETLIST, 1, m, -n); code_byte(ls->fs, n); @@ -282,7 +279,7 @@ static void flush_list (LexState *ls, int m, int n) { static void luaI_registerlocalvar (FuncState *fs, TaggedString *varname, - int line) { + int32 line) { if (fs->maxvars != -1) { /* debug information? */ TProtoFunc *f = fs->f; if (fs->nvars >= fs->maxvars) @@ -295,12 +292,12 @@ static void luaI_registerlocalvar (FuncState *fs, TaggedString *varname, } -static void luaI_unregisterlocalvar (FuncState *fs, int line) { +static void luaI_unregisterlocalvar (FuncState *fs, int32 line) { luaI_registerlocalvar(fs, NULL, line); } -static void store_localvar (LexState *ls, TaggedString *name, int n) { +static void store_localvar (LexState *ls, TaggedString *name, int32 n) { FuncState *fs = ls->fs; if (fs->nlocalvar+n < MAXLOCALS) fs->localvar[fs->nlocalvar+n] = name; @@ -316,17 +313,17 @@ static void add_localvar (LexState *ls, TaggedString *name) { } -static int aux_localname (FuncState *fs, TaggedString *n) { - int i; +static int32 aux_localname (FuncState *fs, TaggedString *n) { + int32 i; for (i=fs->nlocalvar-1; i >= 0; i--) if (n == fs->localvar[i]) return i; /* local var index */ return -1; /* not found */ } -static void singlevar (LexState *ls, TaggedString *n, vardesc *var, int prev) { +static void singlevar (LexState *ls, TaggedString *n, vardesc *var, int32 prev) { FuncState *fs = prev ? ls->fs->prev : ls->fs; - int i = aux_localname(fs, n); + int32 i = aux_localname(fs, n); if (i >= 0) { /* local value */ var->k = VLOCAL; var->info = i; @@ -342,10 +339,10 @@ static void singlevar (LexState *ls, TaggedString *n, vardesc *var, int prev) { } -static int indexupvalue (LexState *ls, TaggedString *n) { +static int32 indexupvalue (LexState *ls, TaggedString *n) { FuncState *fs = ls->fs; vardesc v; - int i; + int32 i; singlevar(ls, n, &v, 1); for (i=0; inupvalues; i++) { if (fs->upvalues[i].k == v.k && fs->upvalues[i].info == v.info) @@ -361,7 +358,7 @@ static int indexupvalue (LexState *ls, TaggedString *n) { static void pushupvalue (LexState *ls, TaggedString *n) { - int i; + int32 i; if (ls->fs->prev == NULL) luaX_syntaxerror(ls, "cannot access upvalue in main", n->str); if (aux_localname(ls->fs, n) >= 0) @@ -380,7 +377,7 @@ static void check_debugline (LexState *ls) { } -static void adjuststack (LexState *ls, int n) { +static void adjuststack (LexState *ls, int32 n) { if (n > 0) code_oparg(ls, POP, 2, n-1, -n); else if (n < 0) @@ -388,10 +385,10 @@ static void adjuststack (LexState *ls, int n) { } -static void close_exp (LexState *ls, int pc, int nresults) { +static void close_exp (LexState *ls, int32 pc, int32 nresults) { if (pc > 0) { /* expression is an open function call */ Byte *code = ls->fs->f->code; - int nparams = code[pc]; /* save nparams */ + int32 nparams = code[pc]; /* save nparams */ pc += fix_opcode(ls, pc-2, CALLFUNC, 2, nresults); code[pc] = nparams; /* restore nparams */ if (nresults != MULT_RET) @@ -401,8 +398,8 @@ static void close_exp (LexState *ls, int pc, int nresults) { } -static void adjust_mult_assign (LexState *ls, int nvars, listdesc *d) { - int diff = d->n - nvars; +static void adjust_mult_assign (LexState *ls, int32 nvars, listdesc *d) { + int32 diff = d->n - nvars; if (d->pc == 0) { /* list is closed */ /* push or pop eventual difference between list lengths */ adjuststack(ls, diff); @@ -421,7 +418,7 @@ static void adjust_mult_assign (LexState *ls, int nvars, listdesc *d) { } -static void code_args (LexState *ls, int nparams, int dots) { +static void code_args (LexState *ls, int32 nparams, int32 dots) { FuncState *fs = ls->fs; fs->nlocalvar += nparams; /* "self" may already be there */ nparams = fs->nlocalvar; @@ -477,22 +474,22 @@ static void storevar (LexState *ls, vardesc *var) { } -static int fixJump (LexState *ls, int pc, OpCode op, int n) { +static int32 fixJump (LexState *ls, int32 pc, OpCode op, int32 n) { /* jump is relative to position following jump instruction */ return fix_opcode(ls, pc, op, 0, n-(pc+JMPSIZE)); } -static void fix_upjmp (LexState *ls, OpCode op, int pos) { - int delta = ls->fs->pc+JMPSIZE - pos; /* jump is relative */ +static void fix_upjmp (LexState *ls, OpCode op, int32 pos) { + int32 delta = ls->fs->pc+JMPSIZE - pos; /* jump is relative */ if (delta > 255) delta++; code_oparg(ls, op, 0, delta, 0); } -static void codeIf (LexState *ls, int thenAdd, int elseAdd) { +static void codeIf (LexState *ls, int32 thenAdd, int32 elseAdd) { FuncState *fs = ls->fs; - int elseinit = elseAdd+JMPSIZE; + int32 elseinit = elseAdd+JMPSIZE; if (fs->pc == elseinit) { /* no else part */ fs->pc -= JMPSIZE; elseinit = fs->pc; @@ -505,8 +502,8 @@ static void codeIf (LexState *ls, int thenAdd, int elseAdd) { static void func_onstack (LexState *ls, FuncState *func) { FuncState *fs = ls->fs; - int i; - int c = next_constant(fs); + int32 i; + int32 c = next_constant(fs); ttype(&fs->f->consts[c]) = LUA_T_PROTO; fs->f->consts[c].value.tf = func->f; if (func->nupvalues == 0) @@ -560,11 +557,11 @@ static void close_func (LexState *ls) { -static int expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT, DO, NAME, +static int32 expfollow [] = {ELSE, ELSEIF, THEN, IF, WHILE, REPEAT, DO, NAME, LOCAL, FUNCTION, END, UNTIL, RETURN, ')', ']', '}', ';', EOS, ',', 0}; -static int is_in (int tok, int *toks) { - int *t = toks; +static int32 is_in (int32 tok, int32 *toks) { + int32 *t = toks; while (*t) { if (*t == tok) return t-toks; @@ -579,14 +576,14 @@ static void next (LexState *ls) { } -static void error_expected (LexState *ls, int token) { +static void error_expected (LexState *ls, int32 token) { char buff[100], t[TOKEN_LEN]; luaX_token2str(ls, token, t); sprintf(buff, "`%s' expected", t); luaX_error(ls, buff); } -static void error_unmatched (LexState *ls, int what, int who, int where) { +static void error_unmatched (LexState *ls, int32 what, int32 who, int32 where) { if (where == ls->linenumber) error_expected(ls, what); else { @@ -600,13 +597,13 @@ static void error_unmatched (LexState *ls, int what, int who, int where) { } } -static void check (LexState *ls, int c) { +static void check (LexState *ls, int32 c) { if (ls->token != c) error_expected(ls, c); next(ls); } -static void check_match (LexState *ls, int what, int who, int where) { +static void check_match (LexState *ls, int32 what, int32 who, int32 where) { if (ls->token != what) error_unmatched(ls, what, who, where); check_debugline(ls); /* to 'mark' the 'what' */ @@ -623,7 +620,7 @@ static TaggedString *checkname (LexState *ls) { } -static int optional (LexState *ls, int c) { +static int32 optional (LexState *ls, int32 c) { if (ls->token == c) { next(ls); return 1; @@ -666,8 +663,8 @@ static void statlist (LexState *ls) { } } -static int stat (LexState *ls) { - int line = ls->linenumber; /* may be needed for error messages */ +static int32 stat (LexState *ls) { + int32 line = ls->linenumber; /* may be needed for error messages */ FuncState *fs = ls->fs; switch (ls->token) { case IF: { /* stat -> IF ifpart END */ @@ -679,8 +676,8 @@ static int stat (LexState *ls) { case WHILE: { /* stat -> WHILE cond DO block END */ TProtoFunc *f = fs->f; - int while_init = fs->pc; - int cond_end, cond_size; + int32 while_init = fs->pc; + int32 cond_end, cond_size; next(ls); cond_end = cond(ls); check(ls, DO); @@ -703,7 +700,7 @@ static int stat (LexState *ls) { } case REPEAT: { /* stat -> REPEAT block UNTIL exp1 */ - int repeat_init = fs->pc; + int32 repeat_init = fs->pc; next(ls); block(ls); check_match(ls, UNTIL, REPEAT, line); @@ -714,7 +711,7 @@ static int stat (LexState *ls) { } case FUNCTION: { /* stat -> FUNCTION funcname body */ - int needself; + int32 needself; vardesc v; if (ls->fs->prev) /* inside other function? */ return 0; @@ -728,7 +725,7 @@ static int stat (LexState *ls) { case LOCAL: { /* stat -> LOCAL localnamelist decinit */ listdesc d; - int nvars; + int32 nvars; check_debugline(ls); next(ls); nvars = localnamelist(ls); @@ -748,7 +745,7 @@ static int stat (LexState *ls) { close_exp(ls, v.info, 0); } else { - int left = assignment(ls, &v, 1); /* stat -> ['%'] NAME assignment */ + int32 left = assignment(ls, &v, 1); /* stat -> ['%'] NAME assignment */ adjuststack(ls, left); /* remove eventual 'garbage' left on stack */ } return 1; @@ -764,19 +761,19 @@ static int stat (LexState *ls) { } } -static int SaveWord (LexState *ls) { - int res = ls->fs->pc; +static int32 SaveWord (LexState *ls) { + int32 res = ls->fs->pc; check_pc(ls->fs, JMPSIZE); ls->fs->pc += JMPSIZE; /* open space */ return res; } -static int SaveWordPop (LexState *ls) { +static int32 SaveWordPop (LexState *ls) { deltastack(ls, -1); /* pop condition */ return SaveWord(ls); } -static int cond (LexState *ls) { +static int32 cond (LexState *ls) { /* cond -> exp1 */ exp1(ls); return SaveWordPop(ls); @@ -785,16 +782,16 @@ static int cond (LexState *ls) { static void block (LexState *ls) { /* block -> chunk */ FuncState *fs = ls->fs; - int nlocalvar = fs->nlocalvar; + int32 nlocalvar = fs->nlocalvar; chunk(ls); adjuststack(ls, fs->nlocalvar - nlocalvar); for (; fs->nlocalvar > nlocalvar; fs->nlocalvar--) luaI_unregisterlocalvar(fs, ls->linenumber); } -static int funcname (LexState *ls, vardesc *v) { +static int32 funcname (LexState *ls, vardesc *v) { /* funcname -> NAME [':' NAME | '.' NAME] */ - int needself = 0; + int32 needself = 0; singlevar(ls, checkname(ls), v, 0); if (ls->token == ':' || ls->token == '.') { needself = (ls->token == ':'); @@ -806,7 +803,7 @@ static int funcname (LexState *ls, vardesc *v) { return needself; } -static void body (LexState *ls, int needself, int line) { +static void body (LexState *ls, int32 needself, int32 line) { /* body -> '(' parlist ')' chunk END */ FuncState newfs; init_state(ls, &newfs, ls->fs->f->fileName); @@ -824,8 +821,8 @@ static void body (LexState *ls, int needself, int line) { static void ifpart (LexState *ls) { /* ifpart -> cond THEN block [ELSE block | ELSEIF ifpart] */ - int c = cond(ls); - int e; + int32 c = cond(ls); + int32 e; check(ls, THEN); block(ls); e = SaveWord(ls); @@ -872,10 +869,10 @@ static void ret (LexState *ls) { */ #define POW 13 -static int binop [] = {EQ, NE, '>', '<', LE, GE, CONC, +static int32 binop [] = {EQ, NE, '>', '<', LE, GE, CONC, '+', '-', '*', '/', '^', 0}; -static int priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6}; +static int32 priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6}; static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP, LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP}; @@ -883,8 +880,8 @@ static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP, #define MAXOPS 20 typedef struct { - int ops[MAXOPS]; - int top; + int32 ops[MAXOPS]; + int32 top; } stack_op; @@ -900,8 +897,8 @@ static void exp1 (LexState *ls) { static void exp0 (LexState *ls, vardesc *v) { exp2(ls, v); while (ls->token == AND || ls->token == OR) { - int is_and = (ls->token == AND); - int pc; + int32 is_and = (ls->token == AND); + int32 pc; lua_pushvar(ls, v); next(ls); pc = SaveWordPop(ls); @@ -912,7 +909,7 @@ static void exp0 (LexState *ls, vardesc *v) { } -static void push (LexState *ls, stack_op *s, int op) { +static void push (LexState *ls, stack_op *s, int32 op) { if (s->top == MAXOPS) luaX_error(ls, "expression too complex"); s->ops[s->top++] = op; @@ -926,8 +923,8 @@ static void prefix (LexState *ls, stack_op *s) { } } -static void pop_to (LexState *ls, stack_op *s, int prio) { - int op; +static void pop_to (LexState *ls, stack_op *s, int32 prio) { + int32 op; while (s->top > 0 && priority[(op=s->ops[s->top-1])] >= prio) { code_opcode(ls, opcodes[op], optop--; @@ -936,7 +933,7 @@ static void pop_to (LexState *ls, stack_op *s, int prio) { static void exp2 (LexState *ls, vardesc *v) { stack_op s; - int op; + int32 op; s.top = 0; prefix(ls, &s); simpleexp(ls, v); @@ -991,7 +988,7 @@ static void simpleexp (LexState *ls, vardesc *v) { break; case FUNCTION: { /* simpleexp -> FUNCTION body */ - int line = ls->linenumber; + int32 line = ls->linenumber; next(ls); body(ls, 0, line); v->k = VEXP; v->info = 0; @@ -1057,9 +1054,9 @@ static void var_or_func_tail (LexState *ls, vardesc *v) { } } -static int funcparams (LexState *ls, int slf) { +static int32 funcparams (LexState *ls, int32 slf) { FuncState *fs = ls->fs; - int nparams = 1; /* default value */ + int32 nparams = 1; /* default value */ switch (ls->token) { case '(': { /* funcparams -> '(' explist ')' */ listdesc e; @@ -1122,8 +1119,8 @@ static void explist1 (LexState *ls, listdesc *d) { } static void parlist (LexState *ls) { - int nparams = 0; - int dots = 0; + int32 nparams = 0; + int32 dots = 0; switch (ls->token) { case DOTS: /* parlist -> DOTS */ next(ls); @@ -1156,9 +1153,9 @@ static void parlist (LexState *ls) { code_args(ls, nparams, dots); } -static int localnamelist (LexState *ls) { +static int32 localnamelist (LexState *ls) { /* localnamelist -> NAME {',' NAME} */ - int i = 1; + int32 i = 1; store_localvar(ls, checkname(ls), 0); while (ls->token == ',') { next(ls); @@ -1179,8 +1176,8 @@ static void decinit (LexState *ls, listdesc *d) { } } -static int assignment (LexState *ls, vardesc *v, int nvars) { - int left = 0; +static int32 assignment (LexState *ls, vardesc *v, int32 nvars) { + int32 left = 0; /* dotted variables must be stored like regular indexed vars */ if (v->k == VDOT) { code_constant(ls, v->info); @@ -1213,9 +1210,9 @@ static int assignment (LexState *ls, vardesc *v, int nvars) { static void constructor (LexState *ls) { /* constructor -> '{' part [';' part] '}' */ - int line = ls->linenumber; - int pc = SaveWord(ls); - int nelems; + int32 line = ls->linenumber; + int32 pc = SaveWord(ls); + int32 nelems; constdesc cd; deltastack(ls, 1); check(ls, '{'); @@ -1281,9 +1278,9 @@ static void part (LexState *ls, constdesc *cd) { } } -static int recfields (LexState *ls) { +static int32 recfields (LexState *ls) { /* recfields -> { ',' recfield } [','] */ - int n = 1; /* one has been read before */ + int32 n = 1; /* one has been read before */ while (ls->token == ',') { next(ls); if (ls->token == ';' || ls->token == '}') @@ -1297,9 +1294,9 @@ static int recfields (LexState *ls) { return n; } -static int listfields (LexState *ls) { +static int32 listfields (LexState *ls) { /* listfields -> { ',' exp1 } [','] */ - int n = 1; /* one has been read before */ + int32 n = 1; /* one has been read before */ while (ls->token == ',') { next(ls); if (ls->token == ';' || ls->token == '}') diff --git a/engine/lua/lparser.h b/engine/lua/lparser.h index 48e5e72b24a..31b89244125 100644 --- a/engine/lua/lparser.h +++ b/engine/lua/lparser.h @@ -11,7 +11,7 @@ #include "lzio.h" -void luaY_codedebugline (int line); +void luaY_codedebugline (int32 line); TProtoFunc *luaY_parser (ZIO *z); void luaY_error (char *s); void luaY_syntaxerror (char *s, char *token); diff --git a/engine/lua/lrestore.cpp b/engine/lua/lrestore.cpp index 4133b91c1a4..b9dc0001386 100644 --- a/engine/lua/lrestore.cpp +++ b/engine/lua/lrestore.cpp @@ -1,7 +1,3 @@ -#include -#include -#include - #include "ltask.h" #include "lauxlib.h" #include "lmem.h" @@ -17,10 +13,10 @@ SaveRestoreCallback restoreCallback = NULL; struct ArrayIDObj { void *object; - unsigned int idObj; + int32 idObj; }; -static int sortCallback(const void *id1, const void *id2) { +static int32 sortCallback(const void *id1, const void *id2) { if (((ArrayIDObj *)id1)->idObj > ((ArrayIDObj *)id2)->idObj) { return 1; } else if (((ArrayIDObj *)id1)->idObj < ((ArrayIDObj *)id2)->idObj) { @@ -30,10 +26,10 @@ static int sortCallback(const void *id1, const void *id2) { } } -int arrayHashTablesCount = 0; -int arrayProtoFuncsCount = 0; -int arrayClosuresCount = 0; -int arrayStringsCount = 0; +int32 arrayHashTablesCount = 0; +int32 arrayProtoFuncsCount = 0; +int32 arrayClosuresCount = 0; +int32 arrayStringsCount = 0; ArrayIDObj *arrayStrings = NULL; ArrayIDObj *arrayHashTables = NULL; ArrayIDObj *arrayClosures = NULL; @@ -113,33 +109,33 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { L = luaM_new(lua_State); lua_resetglobals(); - restoreFunc(&arrayStringsCount, sizeof(int)); - restoreFunc(&arrayClosuresCount, sizeof(int)); - restoreFunc(&arrayHashTablesCount, sizeof(int)); - restoreFunc(&arrayProtoFuncsCount, sizeof(int)); - int rootGlobalCount; - restoreFunc(&rootGlobalCount, sizeof(int)); + restoreFunc(&arrayStringsCount, sizeof(int32)); + restoreFunc(&arrayClosuresCount, sizeof(int32)); + restoreFunc(&arrayHashTablesCount, sizeof(int32)); + restoreFunc(&arrayProtoFuncsCount, sizeof(int32)); + int32 rootGlobalCount; + restoreFunc(&rootGlobalCount, sizeof(int32)); arrayStrings = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayStringsCount); ArrayIDObj *arraysObj = arrayStrings; - int maxStringsLength; - restoreFunc(&maxStringsLength, sizeof(int)); + int32 maxStringsLength; + restoreFunc(&maxStringsLength, sizeof(int32)); char *tempStringBuffer = (char *)luaM_malloc(maxStringsLength); - int i; + int32 i; for (i = 0; i < arrayStringsCount; i++) { - restoreFunc(&arraysObj->idObj, sizeof(unsigned int)); - int constIndex; - restoreFunc(&constIndex, sizeof(int)); + restoreFunc(&arraysObj->idObj, sizeof(int32)); + int32 constIndex; + restoreFunc(&constIndex, sizeof(int32)); lua_Type tag; - restoreFunc(&tag, sizeof(int)); + restoreFunc(&tag, sizeof(int32)); void *value; restoreFunc(&value, sizeof(void *)); TaggedString *tempString; if (constIndex != -1) { - long length; - restoreFunc(&length, sizeof(long)); + int32 length; + restoreFunc(&length, sizeof(int32)); restoreFunc(tempStringBuffer, length); tempString = luaS_newlstr(tempStringBuffer, length); tempString->u.s.globalval.ttype = tag; @@ -159,14 +155,14 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { } luaM_free(tempStringBuffer); - int l; + int32 l; Closure *tempClosure; arraysObj = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayClosuresCount); arrayClosures = arraysObj; for (i = 0; i < arrayClosuresCount; i++) { - restoreFunc(&arraysObj->idObj, sizeof(unsigned int)); - int countElements; - restoreFunc(&countElements, sizeof(int)); + restoreFunc(&arraysObj->idObj, sizeof(int32)); + int32 countElements; + restoreFunc(&countElements, sizeof(int32)); tempClosure = (Closure *)luaM_malloc((countElements * sizeof(TObject)) + sizeof(Closure)); luaO_insertlist(&L->rootcl, (GCnode *)tempClosure); @@ -183,11 +179,11 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { arraysObj = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayHashTablesCount); arrayHashTables = arraysObj; for (i = 0; i < arrayHashTablesCount; i++) { - restoreFunc(&arraysObj->idObj, sizeof(unsigned int)); + restoreFunc(&arraysObj->idObj, sizeof(int32)); tempHash = luaM_new(Hash); - restoreFunc(&tempHash->nhash, sizeof(int)); - restoreFunc(&tempHash->nuse, sizeof(int)); - restoreFunc(&tempHash->htag, sizeof(int)); + restoreFunc(&tempHash->nhash, sizeof(int32)); + restoreFunc(&tempHash->nuse, sizeof(int32)); + restoreFunc(&tempHash->htag, sizeof(int32)); tempHash->node = hashnodecreate(tempHash->nhash); luaO_insertlist(&L->roottable, (GCnode *)tempHash); @@ -205,12 +201,12 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { arrayProtoFuncs = (ArrayIDObj *)luaM_malloc(sizeof(ArrayIDObj) * arrayProtoFuncsCount); arraysObj = arrayProtoFuncs; for (i = 0; i < arrayProtoFuncsCount; i++) { - restoreFunc(&arraysObj->idObj, sizeof(unsigned int)); + restoreFunc(&arraysObj->idObj, sizeof(int32)); tempProtoFunc = luaM_new(TProtoFunc); luaO_insertlist(&L->rootproto, (GCnode *)tempProtoFunc); restoreFunc(&tempProtoFunc->fileName, sizeof(TaggedString *)); - restoreFunc(&tempProtoFunc->lineDefined, sizeof(int)); - restoreFunc(&tempProtoFunc->nconsts, sizeof(int)); + restoreFunc(&tempProtoFunc->lineDefined, sizeof(int32)); + restoreFunc(&tempProtoFunc->nconsts, sizeof(int32)); tempProtoFunc->consts = (TObject *)luaM_malloc(tempProtoFunc->nconsts * sizeof(TObject)); for (l = 0; l < tempProtoFunc->nconsts; l++) { @@ -218,8 +214,8 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { restoreFunc(&tempProtoFunc->consts[l].value, sizeof(Value)); } - int countVariables; - restoreFunc(&countVariables, sizeof(int)); + int32 countVariables; + restoreFunc(&countVariables, sizeof(int32)); if (countVariables != 0) { tempProtoFunc->locvars = (LocVar *)luaM_malloc(countVariables * sizeof(LocVar)); } else { @@ -228,11 +224,11 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { for (l = 0; l < countVariables; l++) { restoreFunc(&tempProtoFunc->locvars[l].varname, sizeof(TaggedString *)); - restoreFunc(&tempProtoFunc->locvars[l].line, sizeof(int)); + restoreFunc(&tempProtoFunc->locvars[l].line, sizeof(int32)); } - int codeSize; - restoreFunc(&codeSize, sizeof(int)); + int32 codeSize; + restoreFunc(&codeSize, sizeof(int32)); tempProtoFunc->code = (lua_Byte *)luaM_malloc(codeSize); restoreFunc(tempProtoFunc->code, codeSize); arraysObj->object = tempProtoFunc; @@ -318,7 +314,7 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { restoreFunc(&L->errorim.value, sizeof(Value)); recreateObj(&L->errorim); - restoreFunc(&L->IMtable_size, sizeof(int)); + restoreFunc(&L->IMtable_size, sizeof(int32)); L->IMtable = (IM *)luaM_malloc(L->IMtable_size * sizeof(IM)); for (i = 0; i < L->IMtable_size; i++) { IM *im = &L->IMtable[i]; @@ -329,8 +325,8 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { } } - restoreFunc(&L->last_tag, sizeof(int)); - restoreFunc(&L->refSize, sizeof(int)); + restoreFunc(&L->last_tag, sizeof(int32)); + restoreFunc(&L->refSize, sizeof(int32)); L->refArray = (ref *)luaM_malloc(L->refSize * sizeof(ref)); for (i = 0; i < L->refSize; i++) { restoreFunc(&L->refArray[i].o.ttype, sizeof(lua_Type)); @@ -339,22 +335,22 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { restoreFunc(&L->refArray[i].status, sizeof(Status)); } - restoreFunc(&L->GCthreshold, sizeof(unsigned long)); - restoreFunc(&L->nblocks, sizeof(unsigned long)); + restoreFunc(&L->GCthreshold, sizeof(int32)); + restoreFunc(&L->nblocks, sizeof(int32)); - restoreFunc(&L->Mbuffsize, sizeof(int)); + restoreFunc(&L->Mbuffsize, sizeof(int32)); L->Mbuffer = (char *)luaM_malloc(L->Mbuffsize); restoreFunc(L->Mbuffer, L->Mbuffsize); - int MbaseOffset; - restoreFunc(&MbaseOffset, sizeof(int)); + int32 MbaseOffset; + restoreFunc(&MbaseOffset, sizeof(int32)); L->Mbuffbase = MbaseOffset + L->Mbuffer; - restoreFunc(&L->Mbuffnext, sizeof(int)); + restoreFunc(&L->Mbuffnext, sizeof(int32)); - restoreFunc(&globalTaskSerialId, sizeof(int)); + restoreFunc(&globalTaskSerialId, sizeof(int32)); - int countTasks; + int32 countTasks; lua_Task *tempTask = NULL; - restoreFunc(&countTasks, sizeof(int)); + restoreFunc(&countTasks, sizeof(int32)); lua_Task *prevTask = L->root_task; for (l = 0; l < countTasks; l++) { tempTask = luaM_new(lua_Task); @@ -362,13 +358,13 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { prevTask->next = tempTask; prevTask = tempTask; - int stackLastSize; - restoreFunc(&stackLastSize, sizeof(int)); + int32 stackLastSize; + restoreFunc(&stackLastSize, sizeof(int32)); tempTask->stack.stack = (TObject *)luaM_malloc(stackLastSize * sizeof(TObject)); tempTask->stack.last = tempTask->stack.stack + stackLastSize - 1; - int stackTopSize; - restoreFunc(&stackTopSize, sizeof(int)); + int32 stackTopSize; + restoreFunc(&stackTopSize, sizeof(int32)); tempTask->stack.top = tempTask->stack.stack + stackTopSize; for (i = 0; i < stackTopSize; i++) { restoreFunc(&tempTask->stack.stack[i].ttype, sizeof(lua_Type)); @@ -378,21 +374,21 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { restoreFunc(&tempTask->Cstack.base, sizeof(StkId)); restoreFunc(&tempTask->Cstack.lua2C, sizeof(StkId)); - restoreFunc(&tempTask->Cstack.num, sizeof(int)); + restoreFunc(&tempTask->Cstack.num, sizeof(int32)); - restoreFunc(&tempTask->numCblocks, sizeof(int)); + restoreFunc(&tempTask->numCblocks, sizeof(int32)); for (i = 0; i < tempTask->numCblocks; i++) { restoreFunc(&tempTask->Cblocks[i].base, sizeof(StkId)); restoreFunc(&tempTask->Cblocks[i].lua2C, sizeof(StkId)); - restoreFunc(&tempTask->Cblocks[i].num, sizeof(int)); + restoreFunc(&tempTask->Cblocks[i].num, sizeof(int32)); } - int pcOffset, taskCi; - restoreFunc(&tempTask->base_ci_size, sizeof(int)); + int32 pcOffset, taskCi; + restoreFunc(&tempTask->base_ci_size, sizeof(int32)); tempTask->base_ci = (CallInfo *)luaM_malloc(tempTask->base_ci_size * sizeof(CallInfo)); memset(tempTask->base_ci, 0, sizeof(CallInfo) * tempTask->base_ci_size); CallInfo *tempCi = tempTask->base_ci; - int countCi = tempTask->base_ci_size / sizeof(CallInfo); + int32 countCi = tempTask->base_ci_size / sizeof(CallInfo); for (i = 0; i < countCi; i++) { TObject tempObj; tempObj.ttype = LUA_T_CLOSURE; @@ -404,27 +400,27 @@ void lua_Restore(SaveRestoreFunc restoreFunc) { recreateObj(&tempObj); tempCi->tf = (TProtoFunc *)tempObj.value.tf; - restoreFunc(&pcOffset, sizeof(int)); + restoreFunc(&pcOffset, sizeof(int32)); if (pcOffset != 0) tempCi->pc = tempCi->tf->code + pcOffset; else tempCi->pc = NULL; restoreFunc(&tempCi->base, sizeof(StkId)); - restoreFunc(&tempCi->nResults, sizeof(int)); + restoreFunc(&tempCi->nResults, sizeof(int32)); tempCi++; } - restoreFunc(&taskCi, sizeof(int)); + restoreFunc(&taskCi, sizeof(int32)); tempTask->ci = tempTask->base_ci + taskCi; tempTask->end_ci = tempTask->base_ci + countCi; - int Mbasepos; - restoreFunc(&Mbasepos, sizeof(int)); + int32 Mbasepos; + restoreFunc(&Mbasepos, sizeof(int32)); tempTask->Mbuffbase = Mbasepos + tempTask->Mbuffer; - restoreFunc(&tempTask->Mbuffnext, sizeof(int)); + restoreFunc(&tempTask->Mbuffnext, sizeof(int32)); restoreFunc(&tempTask->Tstate, sizeof(TaskState)); - restoreFunc(&tempTask->id, sizeof(int)); + restoreFunc(&tempTask->id, sizeof(int32)); } L->last_task = tempTask; diff --git a/engine/lua/lsave.cpp b/engine/lua/lsave.cpp index d46b281ba41..83132764c62 100644 --- a/engine/lua/lsave.cpp +++ b/engine/lua/lsave.cpp @@ -1,7 +1,3 @@ -#include -#include -#include - #include "ltask.h" #include "lauxlib.h" #include "lmem.h" @@ -18,12 +14,12 @@ static void saveObjectValue(TObject *object, SaveRestoreFunc saveFunc) { saveFunc(&object->ttype, sizeof(lua_Type)); if (object->ttype == LUA_T_CPROTO) { luaL_libList *list = list_of_libs; - unsigned int idObj = 0; + int32 idObj = 0; while (list != NULL) { - for (int l = 0; l < list->number; l++) { + for (int32 l = 0; l < list->number; l++) { if (list->list[l].func == object->value.f) { idObj = (idObj << 16) | l; - saveFunc(&idObj, sizeof(unsigned int)); + saveFunc(&idObj, sizeof(int32)); return; } } @@ -36,7 +32,7 @@ static void saveObjectValue(TObject *object, SaveRestoreFunc saveFunc) { } } -static int opcodeSizeTable[] = { +static int32 opcodeSizeTable[] = { 1, 2, 1, 2, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, @@ -56,12 +52,12 @@ void lua_Save(SaveRestoreFunc saveFunc) { printf("lua_Save() started.\n"); lua_collectgarbage(0); - int i, l; - int countElements = 0; - int maxStringLength = 0; + int32 i, l; + int32 countElements = 0; + int32 maxStringLength = 0; for (i = 0; i < NUM_HASHS; i++) { stringtable *tempStringTable = &L->string_root[i]; - for (int l = 0; l < tempStringTable->size; l++) { + for (int32 l = 0; l < tempStringTable->size; l++) { if ((tempStringTable->hash[l] != NULL) && (tempStringTable->hash[l] != &EMPTY)) { countElements++; if (tempStringTable->hash[l]->constindex != -1) { @@ -73,7 +69,7 @@ void lua_Save(SaveRestoreFunc saveFunc) { } } - saveFunc(&countElements, sizeof(int)); + saveFunc(&countElements, sizeof(int32)); countElements = 0; GCnode *tempNode; @@ -82,7 +78,7 @@ void lua_Save(SaveRestoreFunc saveFunc) { countElements++; tempNode = tempNode->next; } - saveFunc(&countElements, sizeof(int)); + saveFunc(&countElements, sizeof(int32)); countElements = 0; tempNode = L->roottable.next; @@ -90,7 +86,7 @@ void lua_Save(SaveRestoreFunc saveFunc) { countElements++; tempNode = tempNode->next; } - saveFunc(&countElements, sizeof(int)); + saveFunc(&countElements, sizeof(int32)); countElements = 0; tempNode = L->rootproto.next; @@ -98,7 +94,7 @@ void lua_Save(SaveRestoreFunc saveFunc) { countElements++; tempNode = tempNode->next; } - saveFunc(&countElements, sizeof(int)); + saveFunc(&countElements, sizeof(int32)); countElements = 0; tempNode = L->rootglobal.next; @@ -106,9 +102,9 @@ void lua_Save(SaveRestoreFunc saveFunc) { countElements++; tempNode = tempNode->next; } - saveFunc(&countElements, sizeof(int)); + saveFunc(&countElements, sizeof(int32)); - saveFunc(&maxStringLength, sizeof(int)); + saveFunc(&maxStringLength, sizeof(int32)); TaggedString *tempString; for (i = 0; i < NUM_HASHS; i++) { @@ -117,10 +113,10 @@ void lua_Save(SaveRestoreFunc saveFunc) { if ((tempStringTable->hash[l] != NULL) && (tempStringTable->hash[l] != &EMPTY)) { tempString = tempStringTable->hash[l]; saveFunc(&tempString, sizeof(TaggedString *)); - saveFunc(&tempString->constindex, sizeof(int)); + saveFunc(&tempString->constindex, sizeof(int32)); if (tempString->constindex != -1) { saveObjectValue(&tempString->u.s.globalval, saveFunc); - saveFunc(&tempString->u.s.len, sizeof(long)); + saveFunc(&tempString->u.s.len, sizeof(int32)); saveFunc(tempString->str, tempString->u.s.len); } else { if (saveCallback != NULL) { @@ -135,7 +131,7 @@ void lua_Save(SaveRestoreFunc saveFunc) { Closure *tempClosure = (Closure *)L->rootcl.next; while (tempClosure != NULL) { saveFunc(&tempClosure, sizeof(Closure *)); - saveFunc(&tempClosure->nelems, sizeof(int)); + saveFunc(&tempClosure->nelems, sizeof(int32)); for(i = 0; i <= tempClosure->nelems; i++) { saveObjectValue(&tempClosure->consts[i], saveFunc); } @@ -145,16 +141,16 @@ void lua_Save(SaveRestoreFunc saveFunc) { Hash *tempHash = (Hash *)L->roottable.next; while (tempHash != NULL) { saveFunc(&tempHash, sizeof(Hash *)); - saveFunc(&tempHash->nhash, sizeof(unsigned int)); - int countUsedHash = 0; + saveFunc(&tempHash->nhash, sizeof(uint32)); + int32 countUsedHash = 0; for(i = 0; i < tempHash->nhash; i++) { Node *newNode = &tempHash->node[i]; if ((newNode->ref.ttype != LUA_T_NIL) && (newNode->val.ttype != LUA_T_NIL)) { countUsedHash++; } } - saveFunc(&countUsedHash, sizeof(int)); - saveFunc(&tempHash->htag, sizeof(int)); + saveFunc(&countUsedHash, sizeof(int32)); + saveFunc(&tempHash->htag, sizeof(int32)); for (i = 0; i < tempHash->nhash; i++) { Node *newNode = &tempHash->node[i]; if ((newNode->val.ttype != LUA_T_NIL) && (newNode->ref.ttype != LUA_T_NIL)) { @@ -169,31 +165,31 @@ void lua_Save(SaveRestoreFunc saveFunc) { while (tempProtoFunc != NULL) { saveFunc(&tempProtoFunc, sizeof(TProtoFunc *)); saveFunc(&tempProtoFunc->fileName, sizeof(TaggedString *)); - saveFunc(&tempProtoFunc->lineDefined, sizeof(unsigned int)); - saveFunc(&tempProtoFunc->nconsts, sizeof(unsigned int)); + saveFunc(&tempProtoFunc->lineDefined, sizeof(int32)); + saveFunc(&tempProtoFunc->nconsts, sizeof(int32)); for (i = 0; i < tempProtoFunc->nconsts; i++) { saveObjectValue(&tempProtoFunc->consts[i], saveFunc); } - int countVariables = 0; + int32 countVariables = 0; if (tempProtoFunc->locvars) { for (; tempProtoFunc->locvars[countVariables++].line != -1;) { } } - saveFunc(&countVariables, sizeof(int)); + saveFunc(&countVariables, sizeof(int32)); for (i = 0; i < countVariables; i++) { saveFunc(&tempProtoFunc->locvars[i].varname, sizeof(TaggedString *)); - saveFunc(&tempProtoFunc->locvars[i].line, sizeof(int)); + saveFunc(&tempProtoFunc->locvars[i].line, sizeof(int32)); } Byte *codePtr = tempProtoFunc->code + 2; Byte *tmpPtr = codePtr; - int opcodeId; + int32 opcodeId; do { opcodeId = *tmpPtr; tmpPtr += opcodeSizeTable[opcodeId]; } while (opcodeId != ENDCODE); - int codeSize = (tmpPtr - codePtr) + 2; - saveFunc(&codeSize, sizeof(int)); + int32 codeSize = (tmpPtr - codePtr) + 2; + saveFunc(&codeSize, sizeof(int32)); saveFunc(tempProtoFunc->code, codeSize); tempProtoFunc = (TProtoFunc *)tempProtoFunc->head.next; } @@ -207,7 +203,7 @@ void lua_Save(SaveRestoreFunc saveFunc) { saveObjectValue(&L->errorim, saveFunc); IM *tempIm = L->IMtable; - saveFunc(&L->IMtable_size, sizeof(int)); + saveFunc(&L->IMtable_size, sizeof(int32)); for (i = 0; i < L->IMtable_size; i++) { for (l = 0; l < IM_N; l++) { saveObjectValue(&tempIm->int_method[l], saveFunc); @@ -215,58 +211,58 @@ void lua_Save(SaveRestoreFunc saveFunc) { tempIm++; } - saveFunc(&L->last_tag, sizeof(int)); - saveFunc(&L->refSize, sizeof(int)); + saveFunc(&L->last_tag, sizeof(int32)); + saveFunc(&L->refSize, sizeof(int32)); for (i = 0 ; i < L->refSize; i++) { saveObjectValue(&L->refArray[i].o, saveFunc); saveFunc(&L->refArray[i].status, sizeof(Status)); } - saveFunc(&L->GCthreshold, sizeof(unsigned long)); - saveFunc(&L->nblocks, sizeof(unsigned long)); + saveFunc(&L->GCthreshold, sizeof(int32)); + saveFunc(&L->nblocks, sizeof(int32)); - saveFunc(&L->Mbuffsize, sizeof(int)); + saveFunc(&L->Mbuffsize, sizeof(int32)); saveFunc(L->Mbuffer, L->Mbuffsize); - int MbaseOffset = L->Mbuffbase - L->Mbuffer; - saveFunc(&MbaseOffset, sizeof(int)); - saveFunc(&L->Mbuffnext, sizeof(int)); + int32 MbaseOffset = L->Mbuffbase - L->Mbuffer; + saveFunc(&MbaseOffset, sizeof(int32)); + saveFunc(&L->Mbuffnext, sizeof(int32)); - saveFunc(&globalTaskSerialId, sizeof(int)); + saveFunc(&globalTaskSerialId, sizeof(int32)); - int countTasks = 0; + int32 countTasks = 0; lua_Task *tempTask = L->root_task->next; while (tempTask != NULL) { countTasks++; tempTask = tempTask->next; } - saveFunc(&countTasks, sizeof(int)); + saveFunc(&countTasks, sizeof(int32)); tempTask = L->root_task->next; while (tempTask != NULL) { - int stackLastSize = (tempTask->stack.last - tempTask->stack.stack) + 1; - saveFunc(&stackLastSize, sizeof(int)); - int stackTopSize = tempTask->stack.top - tempTask->stack.stack; - saveFunc(&stackTopSize, sizeof(int)); + int32 stackLastSize = (tempTask->stack.last - tempTask->stack.stack) + 1; + saveFunc(&stackLastSize, sizeof(int32)); + int32 stackTopSize = tempTask->stack.top - tempTask->stack.stack; + saveFunc(&stackTopSize, sizeof(int32)); for (i = 0; i < stackTopSize; i++) { saveObjectValue(&tempTask->stack.stack[i], saveFunc); } saveFunc(&tempTask->Cstack.base, sizeof(StkId)); saveFunc(&tempTask->Cstack.lua2C, sizeof(StkId)); - saveFunc(&tempTask->Cstack.num, sizeof(int)); + saveFunc(&tempTask->Cstack.num, sizeof(int32)); - saveFunc(&tempTask->numCblocks, sizeof(int)); + saveFunc(&tempTask->numCblocks, sizeof(int32)); for (i = 0; i < tempTask->numCblocks; i++) { saveFunc(&tempTask->Cblocks[i].base, sizeof(StkId)); saveFunc(&tempTask->Cblocks[i].lua2C, sizeof(StkId)); - saveFunc(&tempTask->Cblocks[i].num, sizeof(int)); + saveFunc(&tempTask->Cblocks[i].num, sizeof(int32)); } - int pcOffset, taskCi = -1; - saveFunc(&tempTask->base_ci_size, sizeof(int)); + int32 pcOffset, taskCi = -1; + saveFunc(&tempTask->base_ci_size, sizeof(int32)); assert(tempTask->base_ci); CallInfo *tempCi = tempTask->base_ci; - int countCi = tempTask->base_ci_size / sizeof(CallInfo); + int32 countCi = tempTask->base_ci_size / sizeof(CallInfo); for (i = 0; i < countCi; i++) { saveFunc(&tempCi->c, sizeof(Closure *)); saveFunc(&tempCi->tf, sizeof(TProtoFunc *)); @@ -274,22 +270,22 @@ void lua_Save(SaveRestoreFunc saveFunc) { pcOffset = tempCi->pc - tempCi->tf->code; else pcOffset = 0; - saveFunc(&pcOffset, sizeof(int)); + saveFunc(&pcOffset, sizeof(int32)); saveFunc(&tempCi->base, sizeof(StkId)); - saveFunc(&tempCi->nResults, sizeof(int)); + saveFunc(&tempCi->nResults, sizeof(int32)); if (tempCi == tempTask->ci) taskCi = i; tempCi++; } assert(taskCi != -1); - saveFunc(&taskCi, sizeof(int)); + saveFunc(&taskCi, sizeof(int32)); MbaseOffset = tempTask->Mbuffbase - tempTask->Mbuffer; - saveFunc(&MbaseOffset, sizeof(int)); - saveFunc(&tempTask->Mbuffnext, sizeof(int)); + saveFunc(&MbaseOffset, sizeof(int32)); + saveFunc(&tempTask->Mbuffnext, sizeof(int32)); saveFunc(&tempTask->Tstate, sizeof(TaskState)); - saveFunc(&tempTask->id, sizeof(int)); + saveFunc(&tempTask->id, sizeof(int32)); tempTask = tempTask->next; } diff --git a/engine/lua/lstate.cpp b/engine/lua/lstate.cpp index 0a49fd7e5c9..a06f963c946 100644 --- a/engine/lua/lstate.cpp +++ b/engine/lua/lstate.cpp @@ -5,7 +5,6 @@ */ -#include #include "lbuiltin.h" #include "ldo.h" #include "lauxlib.h" @@ -22,7 +21,7 @@ lua_State *lua_state = NULL; -int globalTaskSerialId; +int32 globalTaskSerialId; void stderrorim (void); diff --git a/engine/lua/lstate.h b/engine/lua/lstate.h index 2faa57394ca..30cbfa8276b 100644 --- a/engine/lua/lstate.h +++ b/engine/lua/lstate.h @@ -18,7 +18,7 @@ #define GARBAGE_BLOCK 150 -typedef int StkId; /* index to stack elements */ +typedef int32 StkId; /* index to stack elements */ struct Stack { TObject *top; @@ -30,13 +30,13 @@ struct C_Lua_Stack { StkId base; /* when Lua calls C or C calls Lua, points to */ /* the first slot after the last parameter. */ StkId lua2C; /* points to first element of "array" lua2C */ - int num; /* size of "array" lua2C */ + int32 num; /* size of "array" lua2C */ }; typedef struct { - int size; - int nuse; /* number of elements (including EMPTYs) */ + int32 size; + int32 nuse; /* number of elements (including EMPTYs) */ TaggedString **hash; } stringtable; @@ -54,7 +54,7 @@ struct CallInfo { TProtoFunc *tf; /* Set to NULL for C function */ StkId base; Byte *pc; - int nResults; + int32 nResults; }; @@ -66,17 +66,17 @@ struct lua_Task { jmp_buf *errorJmp; struct CallInfo *ci; struct CallInfo *base_ci; - int base_ci_size; + int32 base_ci_size; struct CallInfo *end_ci; char *Mbuffer; char *Mbuffbase; - int Mbuffsize; - int Mbuffnext; + int32 Mbuffsize; + int32 Mbuffnext; struct C_Lua_Stack Cblocks[MAX_C_BLOCKS]; - int numCblocks; + int32 numCblocks; enum TaskState Tstate; struct lua_Task *next; - int id; + int32 id; }; struct lua_State { @@ -86,14 +86,14 @@ struct lua_State { jmp_buf *errorJmp; /* current error recover point */ struct CallInfo *ci; /* call info for current function */ struct CallInfo *base_ci; /* array of CallInfo's */ - int base_ci_size; + int32 base_ci_size; struct CallInfo *end_ci; /* points after end of ci array */ char *Mbuffer; /* global buffer */ char *Mbuffbase; /* current first position of Mbuffer */ - int Mbuffsize; /* size of Mbuffer */ - int Mbuffnext; /* next position to fill in Mbuffer */ + int32 Mbuffsize; /* size of Mbuffer */ + int32 Mbuffnext; /* next position to fill in Mbuffer */ struct C_Lua_Stack Cblocks[MAX_C_BLOCKS]; - int numCblocks; /* number of nested Cblocks */ + int32 numCblocks; /* number of nested Cblocks */ enum TaskState Tstate; /* state of current thread */ /* global state */ struct lua_Task *root_task; /* first task created */ @@ -106,18 +106,18 @@ struct lua_State { GCnode rootglobal; /* list of strings with global values */ stringtable *string_root; /* array of hash tables for strings and udata */ struct IM *IMtable; /* table for tag methods */ - int IMtable_size; /* size of IMtable */ - int last_tag; /* last used tag in IMtable */ + int32 IMtable_size; /* size of IMtable */ + int32 last_tag; /* last used tag in IMtable */ struct ref *refArray; /* locked objects */ - int refSize; /* size of refArray */ - unsigned long GCthreshold; - unsigned long nblocks; /* number of 'blocks' currently allocated */ + int32 refSize; /* size of refArray */ + int32 GCthreshold; + int32 nblocks; /* number of 'blocks' currently allocated */ }; extern lua_State *lua_state; -extern int globalTaskSerialId; +extern int32 globalTaskSerialId; #define L lua_state diff --git a/engine/lua/lstring.cpp b/engine/lua/lstring.cpp index f1d1c3f89a0..a8fa41ef5b3 100644 --- a/engine/lua/lstring.cpp +++ b/engine/lua/lstring.cpp @@ -5,9 +5,6 @@ */ -#include -#include - #include "lmem.h" #include "lobject.h" #include "lstate.h" @@ -27,7 +24,7 @@ TaggedString EMPTY = {{NULL, 2}, 0L, 0, void luaS_init (void) { - int i; + int32 i; L->string_root = luaM_newvector(NUM_HASHS, stringtable); for (i=0; istring_root[i].size = 0; @@ -37,19 +34,19 @@ void luaS_init (void) } -static unsigned long hash_s (const char *s, long l) +static uint32 hash_s (const char *s, int32 l) { - unsigned long h = 0; + uint32 h = 0; while (l--) - h = ((h<<5)-h)^(unsigned char)*(s++); + h = ((h<<5)-h)^(byte)*(s++); return h; } -static int newsize (stringtable *tb) +static int32 newsize (stringtable *tb) { - int size = tb->size; - int realuse = 0; - int i; + int32 size = tb->size; + int32 realuse = 0; + int32 i; /* count how many entries are really in use */ for (i=0; ihash[i] != NULL && tb->hash[i] != &EMPTY) @@ -64,16 +61,16 @@ static int newsize (stringtable *tb) static void grow (stringtable *tb) { - int ns = newsize(tb); + int32 ns = newsize(tb); TaggedString **newhash = luaM_newvector(ns, TaggedString *); - int i; + int32 i; for (i=0; inuse = 0; for (i=0; isize; i++) { if (tb->hash[i] != NULL && tb->hash[i] != &EMPTY) { - int h = tb->hash[i]->hash%ns; + int32 h = tb->hash[i]->hash%ns; while (newhash[h]) h = (h+1)%ns; newhash[h] = tb->hash[i]; @@ -86,7 +83,7 @@ static void grow (stringtable *tb) } -static TaggedString *newone_s (const char *str, long l, unsigned long h) +static TaggedString *newone_s (const char *str, int32 l, uint32 h) { TaggedString *ts = (TaggedString *)luaM_malloc(sizeof(TaggedString)+l); memcpy(ts->str, str, l); @@ -101,7 +98,7 @@ static TaggedString *newone_s (const char *str, long l, unsigned long h) return ts; } -static TaggedString *newone_u (char *buff, int tag, unsigned long h) +static TaggedString *newone_u (char *buff, int32 tag, uint32 h) { TaggedString *ts = luaM_new(TaggedString); ts->u.d.v = buff; @@ -114,14 +111,14 @@ static TaggedString *newone_u (char *buff, int tag, unsigned long h) return ts; } -static TaggedString *insert_s (const char *str, long l, stringtable *tb) +static TaggedString *insert_s (const char *str, int32 l, stringtable *tb) { TaggedString *ts; - unsigned long h = hash_s(str, l); - int size = tb->size; - int i; - int j = -1; - if ((long)tb->nuse*3 >= (long)size*2) { + uint32 h = hash_s(str, l); + int32 size = tb->size; + int32 i; + int32 j = -1; + if ((int32)tb->nuse*3 >= size*2) { grow(tb); size = tb->size; } @@ -142,14 +139,14 @@ static TaggedString *insert_s (const char *str, long l, stringtable *tb) return ts; } -static TaggedString *insert_u (void *buff, int tag, stringtable *tb) +static TaggedString *insert_u (void *buff, int32 tag, stringtable *tb) { TaggedString *ts; unsigned long h = (unsigned long)buff; - int size = tb->size; - int i; - int j = -1; - if ((long)tb->nuse*3 >= (long)size*2) { + int32 size = tb->size; + int32 i; + int32 j = -1; + if (tb->nuse*3 >= size*2) { grow(tb); size = tb->size; } @@ -171,14 +168,14 @@ static TaggedString *insert_u (void *buff, int tag, stringtable *tb) return ts; } -TaggedString *luaS_createudata (void *udata, int tag) +TaggedString *luaS_createudata (void *udata, int32 tag) { return insert_u(udata, tag, &L->string_root[(unsigned long)udata%NUM_HASHS]); } -TaggedString *luaS_newlstr (const char *str, long l) +TaggedString *luaS_newlstr (const char *str, int32 l) { - int i = (l==0)?0:(unsigned char)str[0]; + int32 i = (l==0)?0:(byte)str[0]; return insert_s(str, l, &L->string_root[i%NUM_HASHS]); } @@ -225,11 +222,11 @@ static void remove_from_list (GCnode *l) TaggedString *luaS_collector (void) { TaggedString *frees = NULL; - int i; + int32 i; remove_from_list(&(L->rootglobal)); for (i=0; istring_root[i]; - int j; + int32 j; for (j=0; jsize; j++) { TaggedString *t = tb->hash[j]; if (t == NULL) continue; @@ -249,11 +246,11 @@ TaggedString *luaS_collector (void) TaggedString *luaS_collectudata (void) { TaggedString *frees = NULL; - int i; + int32 i; L->rootglobal.next = NULL; /* empty list of globals */ for (i=0; istring_root[i]; - int j; + int32 j; for (j=0; jsize; j++) { TaggedString *t = tb->hash[j]; if (t == NULL || t == &EMPTY || t->constindex != -1) @@ -269,10 +266,10 @@ TaggedString *luaS_collectudata (void) void luaS_freeall (void) { - int i; + int32 i; for (i=0; istring_root[i]; - int j; + int32 j; for (j=0; jsize; j++) { TaggedString *t = tb->hash[j]; if (t == &EMPTY) continue; @@ -294,7 +291,7 @@ void luaS_rawsetglobal (TaggedString *ts, TObject *newval) } -char *luaS_travsymbol (int (*fn)(TObject *)) +char *luaS_travsymbol (int32 (*fn)(TObject *)) { TaggedString *g; for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next) @@ -304,7 +301,7 @@ char *luaS_travsymbol (int (*fn)(TObject *)) } -int luaS_globaldefined (const char *name) +int32 luaS_globaldefined (const char *name) { TaggedString *ts = luaS_new(name); return ts->u.s.globalval.ttype != LUA_T_NIL; diff --git a/engine/lua/lstring.h b/engine/lua/lstring.h index 7ac2be6d618..9186794658c 100644 --- a/engine/lua/lstring.h +++ b/engine/lua/lstring.h @@ -12,15 +12,15 @@ void luaS_init (void); -TaggedString *luaS_createudata (void *udata, int tag); +TaggedString *luaS_createudata (void *udata, int32 tag); TaggedString *luaS_collector (void); void luaS_free (TaggedString *l); -TaggedString *luaS_newlstr (const char *str, long l); +TaggedString *luaS_newlstr (const char *str, int32 l); TaggedString *luaS_new (const char *str); TaggedString *luaS_newfixedstring (const char *str); void luaS_rawsetglobal (TaggedString *ts, TObject *newval); -char *luaS_travsymbol (int (*fn)(TObject *)); -int luaS_globaldefined (const char *name); +char *luaS_travsymbol (int32 (*fn)(TObject *)); +int32 luaS_globaldefined (const char *name); TaggedString *luaS_collectudata (void); void luaS_freeall (void); diff --git a/engine/lua/lstrlib.cpp b/engine/lua/lstrlib.cpp index c1736a14998..b689b359583 100644 --- a/engine/lua/lstrlib.cpp +++ b/engine/lua/lstrlib.cpp @@ -5,18 +5,13 @@ */ -#include -#include -#include -#include - #include "lauxlib.h" #include "lua.h" #include "lualib.h" -static void addnchar (const char *s, int n) +static void addnchar (const char *s, int32 n) { char *b = luaL_openspace(n); memcpy(b, s, n); @@ -26,7 +21,7 @@ static void addnchar (const char *s, int n) static void str_len (void) { - long l; + int32 l; luaL_check_lstr(1, &l); lua_pushnumber(l); } @@ -38,7 +33,7 @@ static void closeandpush (void) } -static long posrelat (long pos, long len) +static int32 posrelat (int32 pos, int32 len) { /* relative string position: negative means back from end */ return (pos>=0) ? pos : len+pos+1; @@ -47,10 +42,10 @@ static long posrelat (long pos, long len) static void str_sub (void) { - long l; + int32 l; const char *s = luaL_check_lstr(1, &l); - long start = posrelat((int)luaL_check_number(2), l); - long end = posrelat((int)luaL_opt_number(3, -1), l); + int32 start = posrelat((int32)luaL_check_number(2), l); + int32 end = posrelat((int32)luaL_opt_number(3, -1), l); if (1 <= start && start <= end && end <= l) lua_pushlstring(s+start-1, end-start+1); else lua_pushstring(""); @@ -59,32 +54,32 @@ static void str_sub (void) static void str_lower (void) { - long l; - int i; + int32 l; + int32 i; const char *s = luaL_check_lstr(1, &l); luaL_resetbuffer(); for (i=0; i 0) addnchar(s, l); @@ -94,20 +89,20 @@ static void str_rep (void) static void str_byte (void) { - long l; + int32 l; const char *s = luaL_check_lstr(1, &l); - long pos = posrelat((int)luaL_opt_number(2, 1), l); + int32 pos = posrelat((int32)luaL_opt_number(2, 1), l); luaL_arg_check(0level; i++) lua_pushlstring(cap->capture[i].init, cap->capture[i].len); } -static int check_cap (int l, struct Capture *cap) +static int32 check_cap (int32 l, struct Capture *cap) { l -= '1'; if (!(0 <= l && l < cap->level && cap->capture[l].len != -1)) @@ -152,9 +147,9 @@ static int check_cap (int l, struct Capture *cap) } -static int capture_to_close (struct Capture *cap) +static int32 capture_to_close (struct Capture *cap) { - int level = cap->level; + int32 level = cap->level; for (level--; level>=0; level--) if (cap->capture[level].len == -1) return level; lua_error("invalid pattern capture"); @@ -168,10 +163,10 @@ static const char *bracket_end (const char *p) } -static int matchclass (int c, int cl) +static int32 matchclass (int32 c, int32 cl) { - int res; - switch (tolower(cl)) { + int32 res; + switch (tolower((int)cl)) { case 'a' : res = isalpha(c); break; case 'c' : res = iscntrl(c); break; case 'd' : res = isdigit(c); break; @@ -183,11 +178,11 @@ static int matchclass (int c, int cl) case 'z' : res = (c == '\0'); break; default: return (cl == c); } - return (islower((unsigned char)cl) ? res : !res); + return (islower((byte)cl) ? res : !res); } -int luaI_singlematch (int c, const char *p, const char **ep) +int32 luaI_singlematch (int32 c, const char *p, const char **ep) { switch (*p) { case '.': /* matches any char */ @@ -200,38 +195,38 @@ int luaI_singlematch (int c, const char *p, const char **ep) if (*(++p) == '\0') luaL_verror("incorrect pattern (ends with `%c')", ESC); *ep = p+1; - return matchclass(c, (unsigned char)*p); + return matchclass(c, (byte)*p); case '[': { const char *end = bracket_end(p+1); - int sig = *(p+1) == '^' ? (p++, 0) : 1; + int32 sig = *(p+1) == '^' ? (p++, 0) : 1; if (end == NULL) lua_error("incorrect pattern (missing `]')"); *ep = end+1; while (++p < end) { if (*p == ESC) { - if (((p+1) < end) && matchclass(c, (unsigned char)*++p)) + if (((p+1) < end) && matchclass(c, (byte)*++p)) return sig; } else if ((*(p+1) == '-') && (p+2 < end)) { p+=2; - if ((unsigned char)*(p-2) <= c && c <= (unsigned char)*p) + if ((byte)*(p-2) <= c && c <= (byte)*p) return sig; } - else if ((unsigned char)*p == c) return sig; + else if ((byte)*p == c) return sig; } return !sig; } default: *ep = p+1; - return ((unsigned char)*p == c); + return ((byte)*p == c); } } -static const char *matchbalance (const char *s, int b, int e, struct Capture *cap) +static const char *matchbalance (const char *s, int32 b, int32 e, struct Capture *cap) { if (*s != b) return NULL; else { - int cont = 1; + int32 cont = 1; while (++s < cap->src_end) { if (*s == e) { if (--cont == 0) return s+1; @@ -247,9 +242,9 @@ static const char *matchitem (const char *s, const char *p, struct Capture *cap, { if (*p == ESC) { p++; - if (isdigit((unsigned char)*p)) { /* capture */ - int l = check_cap(*p, cap); - int len = cap->capture[l].len; + if (isdigit((byte)*p)) { /* capture */ + int32 l = check_cap(*p, cap); + int32 len = cap->capture[l].len; *ep = p+1; if (cap->src_end-s >= len && memcmp(cap->capture[l].init, s, len) == 0) return s+len; @@ -265,7 +260,7 @@ static const char *matchitem (const char *s, const char *p, struct Capture *cap, else p--; /* and go through */ } /* "luaI_singlematch" sets "ep" (so must be called even when *s == 0) */ - return (luaI_singlematch((unsigned char)*s, p, ep) && ssrc_end) ? + return (luaI_singlematch((byte)*s, p, ep) && ssrc_end) ? s+1 : NULL; } @@ -285,7 +280,7 @@ static const char *match (const char *s, const char *p, struct Capture *cap) return res; } case ')': { /* end capture */ - int l = capture_to_close(cap); + int32 l = capture_to_close(cap); const char *res; cap->capture[l].len = s - cap->capture[l].init; /* close capture */ if ((res = match(s, p+1, cap)) == NULL) /* match failed? */ @@ -334,10 +329,10 @@ static const char *match (const char *s, const char *p, struct Capture *cap) static void str_find (void) { - long l; + int32 l; const char *s = luaL_check_lstr(1, &l); const char *p = luaL_check_string(2); - long init = posrelat((int)luaL_opt_number(3, 1), l) - 1; + int32 init = posrelat((int32)luaL_opt_number(3, 1), l) - 1; struct Capture cap; luaL_arg_check(0 <= init && init <= l, 3, "out of range"); if (lua_getparam(4) != LUA_NOOBJECT || @@ -350,7 +345,7 @@ static void str_find (void) } } else { - int anchor = (*p == '^') ? (p++, 1) : 0; + int32 anchor = (*p == '^') ? (p++, 1) : 0; const char *s1=s+init; cap.src_end = s+l; do { @@ -372,17 +367,17 @@ static void add_s (lua_Object newp, struct Capture *cap) { if (lua_isstring(newp)) { const char *news = lua_getstring(newp); - int l = lua_strlen(newp); - int i; + int32 l = lua_strlen(newp); + int32 i; for (i=0; icapture[level].init, cap->capture[level].len); } } @@ -390,8 +385,8 @@ static void add_s (lua_Object newp, struct Capture *cap) } else { /* is a function */ lua_Object res; - int status; - int oldbuff; + int32 status; + int32 oldbuff; lua_beginblock(); push_captures(cap); /* function may use buffer, so save it and create a new one */ @@ -413,13 +408,13 @@ static void add_s (lua_Object newp, struct Capture *cap) static void str_gsub (void) { - long srcl; + int32 srcl; const char *src = luaL_check_lstr(1, &srcl); const char *p = luaL_check_string(2); lua_Object newp = lua_getparam(3); - int max_s = (int)luaL_opt_number(4, srcl+1); - int anchor = (*p == '^') ? (p++, 1) : 0; - int n = 0; + int32 max_s = (int32)luaL_opt_number(4, srcl+1); + int32 anchor = (*p == '^') ? (p++, 1) : 0; + int32 n = 0; struct Capture cap; luaL_arg_check(lua_isstring(newp) || lua_isfunction(newp), 3, "string or function expected"); @@ -461,7 +456,7 @@ static void luaI_addquoted (const char *s) static void str_format (void) { - int arg = 1; + int32 arg = 1; const char *strfrmt = luaL_check_string(arg); struct Capture cap; cap.src_end = strfrmt+strlen(strfrmt)+1; @@ -477,7 +472,7 @@ static void str_format (void) const char *initf = strfrmt; form[0] = '%'; cap.level = 0; - if (isdigit((unsigned char)initf[0]) && initf[1] == '$') { + if (isdigit((byte)initf[0]) && initf[1] == '$') { arg = initf[0] - '0'; initf += 2; /* skip the 'n$' */ } diff --git a/engine/lua/ltable.cpp b/engine/lua/ltable.cpp index 479252b2212..407413e6817 100644 --- a/engine/lua/ltable.cpp +++ b/engine/lua/ltable.cpp @@ -59,14 +59,14 @@ static long int hashindex (TObject *ref) } -int present (Hash *t, TObject *key) +int32 present (Hash *t, TObject *key) { - int tsize = nhash(t); + int32 tsize = nhash(t); long int h = hashindex(key); - int h1 = h%tsize; + int32 h1 = h%tsize; TObject *rf = ref(node(t, h1)); if (ttype(rf) != LUA_T_NIL && !luaO_equalObj(key, rf)) { - int h2 = h%(tsize-2) + 1; + int32 h2 = h%(tsize-2) + 1; do { h1 += h2; if (h1 >= tsize) h1 -= tsize; @@ -80,10 +80,10 @@ int present (Hash *t, TObject *key) /* ** Alloc a vector node */ -Node *hashnodecreate (int nhash) +Node *hashnodecreate (int32 nhash) { Node *v = luaM_newvector(nhash, Node); - int i; + int32 i; for (i=0; inode; - int size = nhash(t); - int realuse = 0; - int i; + int32 size = nhash(t); + int32 realuse = 0; + int32 i; for (i=0; i= tsize) return NULL; n = node(t, i); @@ -210,7 +210,7 @@ Node *luaH_next (TObject *o, TObject *r) if (ttype(r) == LUA_T_NIL) return hashnext(t, 0); else { - int i = present(t, r); + int32 i = present(t, r); Node *n = node(t, i); luaL_arg_check(ttype(ref(n))!=LUA_T_NIL && ttype(val(n))!=LUA_T_NIL, 2, "key not found"); diff --git a/engine/lua/ltable.h b/engine/lua/ltable.h index 6e01165cfab..b986c949095 100644 --- a/engine/lua/ltable.h +++ b/engine/lua/ltable.h @@ -15,12 +15,12 @@ #define val(n) (&(n)->val) #define nhash(t) ((t)->nhash) -Hash *luaH_new (int nhash); +Hash *luaH_new (int32 nhash); void luaH_free (Hash *frees); TObject *luaH_get (Hash *t, TObject *ref); TObject *luaH_set (Hash *t, TObject *ref); Node *luaH_next (TObject *o, TObject *r); -Node *hashnodecreate (int nhash); -int present (Hash *t, TObject *key); +Node *hashnodecreate (int32 nhash); +int32 present (Hash *t, TObject *key); #endif diff --git a/engine/lua/ltask.cpp b/engine/lua/ltask.cpp index 40189d38d0b..2757dd0061d 100644 --- a/engine/lua/ltask.cpp +++ b/engine/lua/ltask.cpp @@ -44,7 +44,7 @@ void start_script (void) { new_task = luaI_newtask(); /* Put the function and arguments onto the new task's stack */ - for (int i = 0; i < old_task->Cstack.num; i++) { + for (int32 i = 0; i < old_task->Cstack.num; i++) { *(L->stack.top) = *(old_task->stack.stack + old_task->Cstack.lua2C + i); incr_top; } @@ -71,7 +71,7 @@ void start_script (void) { void stop_script (void) { struct lua_Task *prev, *t; TObject *f = L->stack.stack + L->Cstack.lua2C; - int match = 0; + int32 match = 0; if ((f == LUA_NOOBJECT) || (ttype(f) != LUA_T_CLOSURE && ttype(f) != LUA_T_PROTO && ttype(f) != LUA_T_TASK)) lua_error("Bad argument to stop_script"); @@ -86,7 +86,7 @@ void stop_script (void) { match = (ttype(t->stack.stack) == LUA_T_PMARK && tfvalue(t->stack.stack) == tfvalue(f)); break; case LUA_T_TASK: - match = (t->id == (int)nvalue(f)); + match = (t->id == (int32)nvalue(f)); break; default: /* Shut up gcc */ break; @@ -120,7 +120,7 @@ void next_script (void) { if (ttype(f) == LUA_T_NIL) { t = L->root_task; } else if (ttype(f) == LUA_T_TASK) { - int taskId = (int)nvalue(f); + int32 taskId = (int32)nvalue(f); for (t = L->root_task->next; t != NULL; t = t->next) { if (t->id == taskId) break; @@ -150,7 +150,7 @@ void identify_script (void) { lua_error("Bad argument to identify_script"); } - int taskId = (int)nvalue(f); + int32 taskId = (int32)nvalue(f); for (t = L->root_task->next; t != NULL; t = t->next) { if (t->id == taskId) break; @@ -167,7 +167,7 @@ void identify_script (void) { void find_script (void) { struct lua_Task *t = NULL, *foundTask = NULL; TObject *f = L->stack.stack + L->Cstack.lua2C; - int countTasks = 0, taskId; + int32 countTasks = 0, taskId; switch (ttype(f)) { case LUA_T_CLOSURE: @@ -189,7 +189,7 @@ void find_script (void) { t = foundTask; break; case LUA_T_TASK: - taskId = (int)nvalue(f); + taskId = (int32)nvalue(f); for (t = L->root_task->next; t != NULL; t = t->next) { if ((t->id == taskId) && (t->Tstate != DONE)) { ttype(L->stack.top) = LUA_T_TASK; diff --git a/engine/lua/ltask.h b/engine/lua/ltask.h index 3a618da4dc5..730343f6f87 100644 --- a/engine/lua/ltask.h +++ b/engine/lua/ltask.h @@ -4,7 +4,7 @@ #include "lua.h" #include "lstate.h" -extern int task_tag; +extern int32 task_tag; void start_script (void); void stop_script (void); diff --git a/engine/lua/ltm.cpp b/engine/lua/ltm.cpp index 638d1aa18f0..61be43d11cb 100644 --- a/engine/lua/ltm.cpp +++ b/engine/lua/ltm.cpp @@ -5,10 +5,6 @@ */ -#include -#include -#include - #include "lauxlib.h" #include "lmem.h" #include "lobject.h" @@ -23,9 +19,9 @@ const char *luaT_eventname[] = { /* ORDER IM */ }; -static int luaI_checkevent (const char *name, const char *list[]) +static int32 luaI_checkevent (const char *name, const char *list[]) { - int e = luaL_findstring(name, list); + int32 e = luaL_findstring(name, list); if (e < 0) luaL_verror("`%.50s' is not a valid event name", name); return e; @@ -48,15 +44,15 @@ static char validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */ }; -static int validevent (int t, int e) +static int32 validevent (int32 t, int32 e) { /* ORDER LUA_T */ return (t < LUA_T_NIL) ? 1 : validevents[-t][e]; } -static void init_entry (int tag) +static void init_entry (int32 tag) { - int i; + int32 i; for (i=0; iIMtable_size = NUM_TAGS*2; L->last_tag = -(NUM_TAGS-1); L->IMtable = luaM_newvector(L->IMtable_size, struct IM); @@ -73,7 +69,7 @@ void luaT_init (void) } -int lua_newtag (void) +int32 lua_newtag (void) { --L->last_tag; if ((-L->last_tag) >= L->IMtable_size) @@ -84,22 +80,22 @@ int lua_newtag (void) } -static void checktag (int tag) +static void checktag (int32 tag) { if (!(L->last_tag <= tag && tag <= 0)) luaL_verror("%d is not a valid tag", tag); } -void luaT_realtag (int tag) +void luaT_realtag (int32 tag) { if (!(L->last_tag <= tag && tag < LUA_T_NIL)) luaL_verror("tag %d is not result of `newtag'", tag); } -int lua_copytagmethods (int tagto, int tagfrom) +int32 lua_copytagmethods (int32 tagto, int32 tagfrom) { - int e; + int32 e; checktag(tagto); checktag(tagfrom); for (e=0; evalue.a->htag; case LUA_T_USERDATA: { - int tag = o->value.ts->u.d.tag; + int32 tag = o->value.ts->u.d.tag; return (tag >= 0) ? LUA_T_USERDATA : tag; } case LUA_T_CLOSURE: @@ -133,9 +129,9 @@ int luaT_efectivetag (TObject *o) } -TObject *luaT_gettagmethod (int t, const char *event) +TObject *luaT_gettagmethod (int32 t, const char *event) { - int e = luaI_checkevent(event, luaT_eventname); + int32 e = luaI_checkevent(event, luaT_eventname); checktag(t); if (validevent(t, e)) return luaT_getim(t,e); @@ -144,10 +140,10 @@ TObject *luaT_gettagmethod (int t, const char *event) } -void luaT_settagmethod (int t, const char *event, TObject *func) +void luaT_settagmethod (int32 t, const char *event, TObject *func) { TObject temp = *func; - int e = luaI_checkevent(event, luaT_eventname); + int32 e = luaI_checkevent(event, luaT_eventname); checktag(t); if (!validevent(t, e)) luaL_verror("settagmethod: cannot change tag method `%.20s' for tag %d", @@ -157,13 +153,13 @@ void luaT_settagmethod (int t, const char *event, TObject *func) } -const char *luaT_travtagmethods (int (*fn)(TObject *)) +const char *luaT_travtagmethods (int32 (*fn)(TObject *)) { - int e; + int32 e; if (fn(&L->errorim)) return "error"; for (e=IM_GETTABLE; e<=IM_FUNCTION; e++) { /* ORDER IM */ - int t; + int32 t; for (t=0; t>=L->last_tag; t--) if (fn(luaT_getim(t,e))) return luaT_eventname[e]; @@ -201,7 +197,7 @@ void typeFB (void) static void fillvalids (IMS e, TObject *func) { - int t; + int32 t; for (t=LUA_T_NIL; t<=LUA_T_USERDATA; t++) if (validevent(t, e)) *luaT_getim(t, e) = *func; @@ -228,7 +224,7 @@ void luaT_setfallback (void) replace = nilFB; break; case 2: { /* old arith fallback */ - int i; + int32 i; oldfunc = *luaT_getim(LUA_T_NUMBER, IM_POW); for (i=IM_ADD; i<=IM_UNM; i++) /* ORDER IM */ fillvalids(i, luaA_Address(func)); @@ -236,7 +232,7 @@ void luaT_setfallback (void) break; } case 3: { /* old order fallback */ - int i; + int32 i; oldfunc = *luaT_getim(LUA_T_NIL, IM_LT); for (i=IM_LT; i<=IM_GE; i++) /* ORDER IM */ fillvalids(i, luaA_Address(func)); @@ -244,7 +240,7 @@ void luaT_setfallback (void) break; } default: { - int e; + int32 e; if ((e = luaL_findstring(name, luaT_eventname)) >= 0) { oldfunc = *luaT_getim(LUA_T_NIL, e); fillvalids(e, luaA_Address(func)); diff --git a/engine/lua/ltm.h b/engine/lua/ltm.h index dbfc1204207..e9cd11b50dd 100644 --- a/engine/lua/ltm.h +++ b/engine/lua/ltm.h @@ -35,7 +35,7 @@ typedef enum { IM_GC, IM_FUNCTION } eIMS; -typedef int IMS; +typedef int32 IMS; #define IM_N 18 @@ -52,11 +52,11 @@ extern const char *luaT_eventname[]; void luaT_init (void); -void luaT_realtag (int tag); -int luaT_efectivetag (TObject *o); -void luaT_settagmethod (int t, const char *event, TObject *func); -TObject *luaT_gettagmethod (int t, const char *event); -const char *luaT_travtagmethods (int (*fn)(TObject *)); +void luaT_realtag (int32 tag); +int32 luaT_efectivetag (TObject *o); +void luaT_settagmethod (int32 t, const char *event, TObject *func); +TObject *luaT_gettagmethod (int32 t, const char *event); +const char *luaT_travtagmethods (int32 (*fn)(TObject *)); void luaT_setfallback (void); /* only if LUA_COMPAT2_5 */ diff --git a/engine/lua/lua.h b/engine/lua/lua.h index dae5d17304f..d99f069ecab 100644 --- a/engine/lua/lua.h +++ b/engine/lua/lua.h @@ -7,6 +7,7 @@ ** See Copyright Notice at the end of this file */ +#include "common\sys.h" #ifndef lua_h #define lua_h @@ -19,14 +20,14 @@ #define LUA_ANYTAG (-1) -typedef void (*lua_CFunction) (void); -typedef unsigned int lua_Object; +typedef void (*lua_CFunction)(void); +typedef uint32 lua_Object; typedef struct lua_State lua_State; extern lua_State *lua_state; -typedef void (*SaveRestoreFunc)(void *, int); -typedef int (*SaveRestoreCallback)(int, int, SaveRestoreFunc); +typedef void (*SaveRestoreFunc)(void *, int32); +typedef int32 (*SaveRestoreCallback)(int32, int32, SaveRestoreFunc); extern SaveRestoreCallback saveCallback; extern SaveRestoreCallback restoreCallback; @@ -40,50 +41,50 @@ void lua_open (void); void lua_close (void); lua_State *lua_setstate (lua_State *st); -lua_Object lua_settagmethod (int tag, const char *event); /* In: new method */ -lua_Object lua_gettagmethod (int tag, const char *event); +lua_Object lua_settagmethod (int32 tag, const char *event); /* In: new method */ +lua_Object lua_gettagmethod (int32 tag, const char *event); lua_Object lua_seterrormethod (void); /* In: new method */ -int lua_newtag (void); -int lua_copytagmethods (int tagto, int tagfrom); -void lua_settag (int tag); /* In: object */ +int32 lua_newtag (void); +int32 lua_copytagmethods (int32 tagto, int32 tagfrom); +void lua_settag (int32 tag); /* In: object */ void lua_error (const char *s); -int lua_dofile (const char *filename); /* Out: returns */ -int lua_dostring (const char *string); /* Out: returns */ -int lua_dobuffer (const char *buff, int size, const char *name); +int32 lua_dofile (const char *filename); /* Out: returns */ +int32 lua_dostring (const char *string); /* Out: returns */ +int32 lua_dobuffer (const char *buff, int32 size, const char *name); /* Out: returns */ -int lua_callfunction (lua_Object f); +int32 lua_callfunction (lua_Object f); /* In: parameters; Out: returns */ void lua_beginblock (void); void lua_endblock (void); -lua_Object lua_lua2C (int number); +lua_Object lua_lua2C (int32 number); #define lua_getparam(_) lua_lua2C(_) #define lua_getresult(_) lua_lua2C(_) -int lua_isnil (lua_Object object); -int lua_istable (lua_Object object); -int lua_isuserdata (lua_Object object); -int lua_iscfunction (lua_Object object); -int lua_isnumber (lua_Object object); -int lua_isstring (lua_Object object); -int lua_isfunction (lua_Object object); +int32 lua_isnil (lua_Object object); +int32 lua_istable (lua_Object object); +int32 lua_isuserdata (lua_Object object); +int32 lua_iscfunction (lua_Object object); +int32 lua_isnumber (lua_Object object); +int32 lua_isstring (lua_Object object); +int32 lua_isfunction (lua_Object object); double lua_getnumber (lua_Object object); const char *lua_getstring (lua_Object object); -long lua_strlen (lua_Object object); +int32 lua_strlen (lua_Object object); lua_CFunction lua_getcfunction (lua_Object object); void *lua_getuserdata (lua_Object object); void lua_pushnil (void); void lua_pushnumber (double n); -void lua_pushlstring (const char *s, long len); +void lua_pushlstring (const char *s, int32 len); void lua_pushstring (const char *s); -void lua_pushcclosure (lua_CFunction fn, int n); -void lua_pushusertag (void *u, int tag); +void lua_pushcclosure (lua_CFunction fn, int32 n); +void lua_pushusertag (void *u, int32 tag); void lua_pushobject (lua_Object object); lua_Object lua_pop (void); @@ -98,16 +99,16 @@ void lua_rawsettable (void); /* In: table, index, value */ lua_Object lua_gettable (void); /* In: table, index */ lua_Object lua_rawgettable (void); /* In: table, index */ -int lua_tag (lua_Object object); +int32 lua_tag (lua_Object object); -int lua_ref (int lock); /* In: value */ -lua_Object lua_getref (int ref); -void lua_unref (int ref); +int32 lua_ref (int32 lock); /* In: value */ +lua_Object lua_getref (int32 ref); +void lua_unref (int32 ref); lua_Object lua_createtable (void); -long lua_collectgarbage (long limit); +int32 lua_collectgarbage (int32 limit); void lua_runtasks (void); @@ -116,13 +117,13 @@ void current_script (void); /* =============================================================== */ /* some useful macros/derived functions */ -int (lua_call) (char *name); +int32 (lua_call) (char *name); #define lua_call(name) lua_callfunction(lua_getglobal(name)) -void (lua_pushref) (int ref); +void (lua_pushref) (int32 ref); #define lua_pushref(ref) lua_pushobject(lua_getref(ref)) -int (lua_refobject) (lua_Object o, int l); +int32 (lua_refobject) (lua_Object o, int32 l); #define lua_refobject(o,l) (lua_pushobject(o), lua_ref(l)) void (lua_register) (char *n, lua_CFunction f); @@ -134,7 +135,7 @@ void (lua_pushuserdata) (void *u); void (lua_pushcfunction) (lua_CFunction f); #define lua_pushcfunction(f) lua_pushcclosure(f, 0) -int (lua_clonetag) (int t); +int32 (lua_clonetag) (int32 t); #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t)) diff --git a/engine/lua/luadebug.h b/engine/lua/luadebug.h index 937d8d4cb6e..5cfd03f6123 100644 --- a/engine/lua/luadebug.h +++ b/engine/lua/luadebug.h @@ -13,21 +13,21 @@ typedef lua_Object lua_Function; -typedef void (*lua_LHFunction) (int line); -typedef void (*lua_CHFunction) (lua_Function func, const char *file, int line); +typedef void (*lua_LHFunction) (int32 line); +typedef void (*lua_CHFunction) (lua_Function func, const char *file, int32 line); -lua_Function lua_stackedfunction (int level); -void lua_funcinfo (lua_Object func, const char **filename, int *linedefined); -int lua_currentline (lua_Function func); +lua_Function lua_stackedfunction (int32 level); +void lua_funcinfo (lua_Object func, const char **filename, int32 *linedefined); +int32 lua_currentline (lua_Function func); const char *lua_getobjname (lua_Object o, const char **name); -lua_Object lua_getlocal (lua_Function func, int local_number, char **name); -int lua_setlocal (lua_Function func, int local_number); +lua_Object lua_getlocal (lua_Function func, int32 local_number, char **name); +int32 lua_setlocal (lua_Function func, int32 local_number); extern lua_LHFunction lua_linehook; extern lua_CHFunction lua_callhook; -extern int lua_debug; +extern int32 lua_debug; #endif diff --git a/engine/lua/lualib.h b/engine/lua/lualib.h index 7da23c7a2e5..93da82aaca5 100644 --- a/engine/lua/lualib.h +++ b/engine/lua/lualib.h @@ -28,7 +28,7 @@ void lua_mathlibopen (void); /* Auxiliary functions (private) */ -int luaI_singlematch (int c, const char *p, const char **ep); +int32 luaI_singlematch (int32 c, const char *p, const char **ep); #endif diff --git a/engine/lua/lundump.cpp b/engine/lua/lundump.cpp index bff14fd1db8..0ac7eee1f32 100644 --- a/engine/lua/lundump.cpp +++ b/engine/lua/lundump.cpp @@ -4,9 +4,6 @@ ** See Copyright Notice in lua.h */ -#include -#include -#include #include "lauxlib.h" #include "lfunc.h" #include "lmem.h" @@ -20,8 +17,8 @@ static float conv_float(const char *data) { - const unsigned char *udata = (const unsigned char *)(data); - unsigned char fdata[4]; + const byte *udata = (const byte *)(data); + byte fdata[4]; fdata[0] = udata[3]; fdata[1] = udata[2]; fdata[2] = udata[1]; @@ -34,43 +31,43 @@ static void unexpectedEOZ(ZIO* Z) luaL_verror("unexpected end of file in %s",zname(Z)); } -static int ezgetc(ZIO* Z) +static int32 ezgetc(ZIO* Z) { - int c=zgetc(Z); + int32 c=zgetc(Z); if (c==EOZ) unexpectedEOZ(Z); return c; } -static void ezread(ZIO* Z, void* b, int n) +static void ezread(ZIO* Z, void* b, int32 n) { - int r=zread(Z,b,n); + int32 r=zread(Z,b,n); if (r!=0) unexpectedEOZ(Z); } -static unsigned int LoadWord(ZIO* Z) +static uint16 LoadWord(ZIO* Z) { - unsigned int hi=ezgetc(Z); - unsigned int lo=ezgetc(Z); + uint16 hi=ezgetc(Z); + uint16 lo=ezgetc(Z); return (hi<<8)|lo; } -static unsigned long LoadLong(ZIO* Z) +static uint32 LoadLong(ZIO* Z) { - unsigned long hi=LoadWord(Z); - unsigned long lo=LoadWord(Z); + uint32 hi=LoadWord(Z); + uint32 lo=LoadWord(Z); return (hi<<16)|lo; } static float LoadFloat(ZIO* Z) { - unsigned long l=LoadLong(Z); + uint32 l=LoadLong(Z); return conv_float((const char *)&l); } static Byte* LoadCode(ZIO* Z) { - unsigned long size=LoadLong(Z); - unsigned int s=size; + int32 size=LoadLong(Z); + int32 s=size; void* b; if (s!=size) luaL_verror("code too long (%ld bytes) in %s",size,zname(Z)); b=luaM_malloc(size); @@ -80,8 +77,8 @@ static Byte* LoadCode(ZIO* Z) static TaggedString* LoadTString(ZIO* Z) { - int size=LoadWord(Z); - int i; + int32 size=LoadWord(Z); + int32 i; if (size==0) return NULL; else @@ -96,7 +93,7 @@ static TaggedString* LoadTString(ZIO* Z) static void LoadLocals(TProtoFunc* tf, ZIO* Z) { - int i,n=LoadWord(Z); + int32 i,n=LoadWord(Z); if (n==0) return; tf->locvars=luaM_newvector(n+1,LocVar); for (i=0; inconsts=n; if (n==0) return; tf->consts=luaM_newvector(n,TObject); @@ -120,23 +117,23 @@ static void LoadConstants(TProtoFunc* tf, ZIO* Z) { TObject* o=tf->consts+i; ttype(o)=(lua_Type)-ezgetc(Z); - switch ((unsigned)ttype(o)) + switch ((uint32)ttype(o)) { - case (unsigned int)-'N': + case (uint32)-'N': ttype(o)=LUA_T_NUMBER; - case (unsigned int)LUA_T_NUMBER: + case (uint32)LUA_T_NUMBER: doLoadNumber(nvalue(o),Z); break; - case (unsigned int)-'S': + case (uint32)-'S': ttype(o)=LUA_T_STRING; - case (unsigned int)LUA_T_STRING: + case (uint32)LUA_T_STRING: tsvalue(o)=LoadTString(Z); break; - case (unsigned int)-'F': + case (uint32)-'F': ttype(o)=LUA_T_PROTO; - case (unsigned int)LUA_T_PROTO: + case (uint32)LUA_T_PROTO: break; - case (unsigned int)LUA_T_NIL: + case (uint32)LUA_T_NIL: break; default: luaL_verror("bad constant #%d in %s: type=%d [%s]", @@ -152,7 +149,7 @@ static void LoadSubfunctions(TProtoFunc* tf, ZIO* Z) { t = ezgetc(Z); switch (t) { case '#': { - int i = LoadWord(Z); + int32 i = LoadWord(Z); if (ttype(tf->consts+i) != LUA_T_PROTO) luaL_verror("trying to load function into nonfunction constant (type=%d)", ttype(tf->consts+i)); @@ -189,7 +186,7 @@ static void LoadSignature(ZIO* Z) static void LoadHeader(ZIO* Z) { - int version,id,sizeofR; + int32 version,id,sizeofR; #if 0 real f=(real)-TEST_NUMBER,tf=(real)TEST_NUMBER; #endif @@ -233,7 +230,7 @@ static TProtoFunc* LoadChunk(ZIO* Z) */ TProtoFunc* luaU_undump1(ZIO* Z) { - int c=zgetc(Z); + int32 c=zgetc(Z); if (c==ID_CHUNK) return LoadChunk(Z); else if (c!=EOZ) diff --git a/engine/lua/lvm.cpp b/engine/lua/lvm.cpp index 9f9236965a3..51d0aa9740e 100644 --- a/engine/lua/lvm.cpp +++ b/engine/lua/lvm.cpp @@ -5,9 +5,6 @@ */ -#include -#include - #include "lauxlib.h" #include "ldo.h" #include "lfunc.h" @@ -21,10 +18,6 @@ #include "luadebug.h" #include "lvm.h" -#ifdef OLD_ANSI -#define strcoll(a,b) strcmp(a,b) -#endif - #define skip_word(pc) (pc+=2) @@ -44,7 +37,7 @@ static TaggedString *strconc (TaggedString *l, TaggedString *r) } -int luaV_tonumber (TObject *obj) +int32 luaV_tonumber (TObject *obj) { /* LUA_NUMBER */ double t; char c; @@ -60,7 +53,7 @@ int luaV_tonumber (TObject *obj) } -int luaV_tostring (TObject *obj) +int32 luaV_tostring (TObject *obj) { /* LUA_NUMBER */ /* The Lua scripts for Grim Fandango sometimes end up executing str..nil. The nil shows up in the original engine as "(nil)"... */ @@ -74,8 +67,8 @@ int luaV_tostring (TObject *obj) else { char s[60]; real f = nvalue(obj); - int i; - if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int)f) == f) + int32 i; + if ((real)(-MAX_INT) <= f && f <= (real)MAX_INT && (real)(i=(int32)f) == f) sprintf (s, "%d", i); else sprintf (s, NUMBER_FMT, nvalue(obj)); @@ -86,7 +79,7 @@ int luaV_tostring (TObject *obj) } -void luaV_closure (int nelems) +void luaV_closure (int32 nelems) { if (nelems > 0) { struct Stack *S = &L->stack; @@ -111,7 +104,7 @@ void luaV_gettable (void) if (ttype(S->top-2) != LUA_T_ARRAY) /* not a table, get "gettable" method */ im = luaT_getimbyObj(S->top-2, IM_GETTABLE); else { /* object is a table... */ - int tg = (S->top-2)->value.a->htag; + int32 tg = (S->top-2)->value.a->htag; im = luaT_getim(tg, IM_GETTABLE); if (ttype(im) == LUA_T_NIL) { /* and does not have a "gettable" method */ TObject *h = luaH_get(avalue(S->top-2), S->top-1); @@ -143,7 +136,7 @@ void luaV_gettable (void) ** mode = 1: normal store (with tag methods) ** mode = 2: "deep L->stack.stack" store (with tag methods) */ -void luaV_settable (TObject *t, int mode) +void luaV_settable (TObject *t, int32 mode) { struct Stack *S = &L->stack; TObject *im = (mode == 0) ? NULL : luaT_getimbyObj(t, IM_SETTABLE); @@ -228,10 +221,10 @@ static void call_arith (IMS event) } -static int strcomp (char *l, long ll, char *r, long lr) +static int32 strcomp (char *l, int32 ll, char *r, int32 lr) { for (;;) { - long temp = strcoll(l, r); + int32 temp = (int32)strcoll(l, r); if (temp != 0) return temp; /* strings are equal up to a '\0' */ temp = strlen(l); /* index of first '\0' in both strings */ @@ -251,11 +244,11 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal, struct Stack *S = &L->stack; TObject *l = S->top-2; TObject *r = S->top-1; - int result; + int32 result; if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1; else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) - result = strcomp(svalue(l), tsvalue(l)->u.s.len, + result = (int32)strcomp(svalue(l), tsvalue(l)->u.s.len, svalue(r), tsvalue(r)->u.s.len); else { call_binTM(op, "unexpected type in comparison"); @@ -268,10 +261,10 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal, } -void luaV_pack (StkId firstel, int nvararg, TObject *tab) +void luaV_pack (StkId firstel, int32 nvararg, TObject *tab) { TObject *firstelem = L->stack.stack+firstel; - int i; + int32 i; if (nvararg < 0) nvararg = 0; avalue(tab) = luaH_new(nvararg+1); /* +1 for field 'n' */ ttype(tab) = LUA_T_ARRAY; @@ -300,7 +293,7 @@ void luaV_pack (StkId firstel, int nvararg, TObject *tab) StkId luaV_execute (struct CallInfo *ci) { /* Save index in case CallInfo array is realloc'd */ - int ci_index = ci - L->base_ci; + int32 ci_index = ci - L->base_ci; struct Stack *S = &L->stack; /* to optimize */ Closure *cl; TProtoFunc *tf; @@ -316,7 +309,7 @@ StkId luaV_execute (struct CallInfo *ci) pc = L->ci->pc; consts = tf->consts; while (1) { - int aux; + int32 aux; switch ((OpCode)(aux = *pc++)) { case PUSHNIL0: @@ -465,7 +458,7 @@ StkId luaV_execute (struct CallInfo *ci) case SETLIST0: aux = 0; setlist: { - int n = *(pc++); + int32 n = *(pc++); TObject *arr = S->top-n-1; for (; n; n--) { ttype(S->top) = LUA_T_NUMBER; @@ -515,7 +508,7 @@ StkId luaV_execute (struct CallInfo *ci) break; case EQOP: case NEQOP: { - int res = luaO_equalObj(S->top-2, S->top-1); + int32 res = luaO_equalObj(S->top-2, S->top-1); S->top--; if (aux == NEQOP) res = !res; ttype(S->top-1) = res ? LUA_T_NUMBER : LUA_T_NIL; diff --git a/engine/lua/lvm.h b/engine/lua/lvm.h index f49f592c672..49687e7ff2a 100644 --- a/engine/lua/lvm.h +++ b/engine/lua/lvm.h @@ -16,14 +16,14 @@ #define tostring(o) ((ttype(o) != LUA_T_STRING) && (luaV_tostring(o) != 0)) -void luaV_pack (StkId firstel, int nvararg, TObject *tab); -int luaV_tonumber (TObject *obj); -int luaV_tostring (TObject *obj); +void luaV_pack (StkId firstel, int32 nvararg, TObject *tab); +int32 luaV_tonumber (TObject *obj); +int32 luaV_tostring (TObject *obj); void luaV_gettable (void); -void luaV_settable (TObject *t, int mode); +void luaV_settable (TObject *t, int32 mode); void luaV_getglobal (TaggedString *ts); void luaV_setglobal (TaggedString *ts); StkId luaV_execute (struct CallInfo *ci); -void luaV_closure (int nelems); +void luaV_closure (int32 nelems); #endif diff --git a/engine/lua/lzio.cpp b/engine/lua/lzio.cpp index 0adcf349028..797824bc639 100644 --- a/engine/lua/lzio.cpp +++ b/engine/lua/lzio.cpp @@ -15,16 +15,16 @@ /* ----------------------------------------------------- memory buffers --- */ -static int zmfilbuf (ZIO* /*z*/) +static int32 zmfilbuf (ZIO* /*z*/) { return EOZ; } -ZIO* zmopen (ZIO* z, const char* b, int size, const char *name) +ZIO* zmopen (ZIO* z, const char* b, int32 size, const char *name) { if (b==NULL) return NULL; z->n=size; - z->p= (const unsigned char *)b; + z->p= (const byte *)b; z->filbuf=zmfilbuf; z->u=NULL; z->name=name; @@ -41,9 +41,9 @@ ZIO* zsopen (ZIO* z, const char* s, const char *name) /* -------------------------------------------------------------- FILEs --- */ -static int zffilbuf (ZIO* z) +static int32 zffilbuf (ZIO* z) { - int n=fread(z->buffer,1,ZBSIZE,(FILE *)z->u); + int32 n=fread(z->buffer,1,ZBSIZE,(FILE *)z->u); if (n==0) return EOZ; z->n=n-1; z->p=z->buffer; @@ -64,10 +64,10 @@ ZIO* zFopen (ZIO* z, FILE* f, const char *name) /* --------------------------------------------------------------- read --- */ -int zread (ZIO *z, void *b, int n) +int32 zread (ZIO *z, void *b, int n) { while (n) { - int m; + int32 m; if (z->n == 0) { if (z->filbuf(z) == EOZ) return n; /* retorna quantos faltaram ler */ diff --git a/engine/lua/lzio.h b/engine/lua/lzio.h index 6b0f5255410..612f7a11e22 100644 --- a/engine/lua/lzio.h +++ b/engine/lua/lzio.h @@ -8,7 +8,7 @@ #ifndef lzio_h #define lzio_h -#include +#include @@ -24,11 +24,11 @@ typedef struct zio ZIO; ZIO* zFopen (ZIO* z, FILE* f, const char *name); /* open FILEs */ ZIO* zsopen (ZIO* z, const char* s, const char *name); /* string */ -ZIO* zmopen (ZIO* z, const char* b, int size, const char *name); /* memory */ +ZIO* zmopen (ZIO* z, const char* b, int32 size, const char *name); /* memory */ -int zread (ZIO* z, void* b, int n); /* read next n bytes */ +int32 zread (ZIO* z, void* b, int32 n); /* read next n bytes */ -#define zgetc(z) (--(z)->n>=0 ? ((int)*(z)->p++): (z)->filbuf(z)) +#define zgetc(z) (--(z)->n>=0 ? ((int32)*(z)->p++): (z)->filbuf(z)) #define zungetc(z) (++(z)->n,--(z)->p) #define zname(z) ((z)->name) @@ -38,12 +38,12 @@ int zread (ZIO* z, void* b, int n); /* read next n bytes */ #define ZBSIZE 256 /* buffer size */ struct zio { - int n; /* bytes still unread */ - const unsigned char* p; /* current position in buffer */ - int (*filbuf)(ZIO* z); + int32 n; /* bytes still unread */ + const byte* p; /* current position in buffer */ + int32 (*filbuf)(ZIO* z); void* u; /* additional data */ const char *name; - unsigned char buffer[ZBSIZE]; /* buffer */ + byte buffer[ZBSIZE]; /* buffer */ };