[Scummvm-cvs-logs] CVS: residual/lua lrestore.cpp,NONE,1.1 lsave.cpp,NONE,1.1 lauxlib.cpp,1.1,1.2 lauxlib.h,1.1,1.2 lbuiltin.cpp,1.3,1.4 ldo.cpp,1.1,1.2 liolib.cpp,1.1,1.2 lmathlib.cpp,1.1,1.2 lstate.cpp,1.1,1.2 lstate.h,1.1,1.2 lstring.cpp,1.1,1.2 lstring.h,1.1,1.2 ltable.cpp,1.1,1.2 ltable.h,1.1,1.2 ltm.cpp,1.1,1.2 lua.h,1.3,1.4

Pawel Kolodziejski aquadran at users.sourceforge.net
Sat Dec 25 10:24:02 CET 2004


Update of /cvsroot/scummvm/residual/lua
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12626/lua

Modified Files:
	lauxlib.cpp lauxlib.h lbuiltin.cpp ldo.cpp liolib.cpp 
	lmathlib.cpp lstate.cpp lstate.h lstring.cpp lstring.h 
	ltable.cpp ltable.h ltm.cpp lua.h 
Added Files:
	lrestore.cpp lsave.cpp 
Log Message:
- allow reset lua global tables,
- allow access to some static funcs,
- clearing CallInfo structure after alloc and realloc,
- add base_ci_size of base_ci to task and state structure and handle it,
- add PAUSE tag to task,
- store funcs libs into lists,
- added few lua funcs used by engine
- added dummy save/restore callbacks/funcs
- changed restore engine key F5 to F7


--- NEW FILE: lrestore.cpp ---
#include <stdlib.h>
#include <stdio.h>
#include <search.h>
#include <assert.h>

#include "ltask.h"
#include "lauxlib.h"
#include "lmem.h"
#include "ldo.h"
#include "ltm.h"
#include "ltable.h"
#include "lvm.h"
#include "lopcodes.h"
#include "lstring.h"
#include "lua.h"

SaveRestoreCallback restoreCallback = NULL;

void lua_Restore(SaveRestoreFunc restoreFunc) {
}

--- NEW FILE: lsave.cpp ---
#include <stdlib.h>
#include <stdio.h>
#include <search.h>
#include <assert.h>

#include "ltask.h"
#include "lauxlib.h"
#include "lmem.h"
#include "ldo.h"
#include "ltm.h"
#include "ltable.h"
#include "lvm.h"
#include "lopcodes.h"
#include "lstring.h"

SaveRestoreCallback saveCallback = NULL;

void lua_Save(SaveRestoreFunc saveFunc) {
}

Index: lauxlib.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lauxlib.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- lauxlib.cpp	6 Oct 2004 19:07:53 -0000	1.1
+++ lauxlib.cpp	25 Dec 2004 18:23:07 -0000	1.2
@@ -16,7 +16,7 @@
 #include "lauxlib.h"
 #include "lua.h"
 #include "luadebug.h"
-
+#include "lmem.h"
 
 
 int luaL_findstring (char *name, char *list[]) {
@@ -90,12 +90,32 @@
   return o;
 }
 
+luaL_libList *list_of_libs = NULL;
+
+void luaL_addlibtolist(luaL_reg *l, int n) {
+  luaL_libList *list = (luaL_libList *)luaM_malloc(sizeof(luaL_libList));
+  list->list = l;
+  list->number = n;
+  list->next = list_of_libs;
+  list_of_libs = list;
+}
+
+void lua_removelibslists(void) {
+  luaL_libList *list = list_of_libs;
+  while (list) {
+    luaL_libList *nextList = list->next;
+    luaM_free(list);
+    list = nextList;
+  }
+}
+
 void luaL_openlib (struct luaL_reg *l, int n)
 {
   int i;
   lua_open();  /* make sure lua is already open */
   for (i=0; i<n; i++)
     lua_register(l[i].name, l[i].func);
+  luaL_addlibtolist(l, n);
 }
 
 

Index: lauxlib.h
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lauxlib.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- lauxlib.h	6 Oct 2004 19:07:53 -0000	1.1
+++ lauxlib.h	25 Dec 2004 18:23:07 -0000	1.2
@@ -17,11 +17,19 @@
   lua_CFunction func;
 };
 
+struct luaL_libList {
+  luaL_reg *list;
+  int number;
+  luaL_libList *next;
+};
+
+extern luaL_libList *list_of_libs;
 
 #define luaL_arg_check(cond,numarg,extramsg) if (!(cond)) \
                                                luaL_argerror(numarg,extramsg)
 
 void luaL_openlib (struct luaL_reg *l, int n);
+void luaL_addlibtolist(luaL_reg *l, int n);
 void luaL_argerror (int numarg, char *extramsg);
 #define luaL_check_string(n)  (luaL_check_lstr((n), NULL))
 char *luaL_check_lstr (int numArg, long *len);

Index: lbuiltin.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lbuiltin.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- lbuiltin.cpp	6 Nov 2004 14:04:08 -0000	1.3
+++ lbuiltin.cpp	25 Dec 2004 18:23:07 -0000	1.4
@@ -522,12 +522,18 @@
 
 #define INTFUNCSIZE (sizeof(int_funcs)/sizeof(int_funcs[0]))
 
+void gc_task (void);
+
+static luaL_reg gcTaskFuncs[] = {
+  {"gc_task", gc_task}
+};
 
 void luaB_predefine (void)
 {
   /* pre-register mem error messages, to avoid loop when error arises */
   luaS_newfixedstring(tableEM);
   luaS_newfixedstring(memEM);
+  luaL_addlibtolist(gcTaskFuncs, (sizeof(gcTaskFuncs)/sizeof(gcTaskFuncs[0])));
   task_tag = lua_newtag();
   lua_pushcfunction(gc_task);
   lua_settagmethod(task_tag, "gc");

Index: ldo.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/ldo.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ldo.cpp	6 Oct 2004 19:07:53 -0000	1.1
+++ ldo.cpp	25 Dec 2004 18:23:07 -0000	1.2
@@ -18,6 +18,7 @@
 #include "lopcodes.h"
 #include "lparser.h"
 #include "lstate.h"
+#include "ltask.h"
 #include "ltm.h"
 #include "lua.h"
 #include "luadebug.h"
@@ -41,7 +42,7 @@
 ** Error messages
 */
 
-static void stderrorim (void)
+void stderrorim (void)
 {
   fprintf(stderr, "lua error: %s\n", lua_getstring(lua_getparam(1)));
 }
@@ -65,6 +66,8 @@
   L->stack.top = L->stack.stack;
   L->stack.last = L->stack.stack+(STACK_UNIT-1);
   L->base_ci = luaM_newvector(BASIC_CI_SIZE, struct CallInfo);
+  memset(L->base_ci, 0, sizeof(CallInfo) * BASIC_CI_SIZE);
+  L->base_ci_size = sizeof(CallInfo) * BASIC_CI_SIZE; 
   L->ci = L->base_ci;
   L->ci->tf = NULL;
   L->end_ci = L->base_ci + BASIC_CI_SIZE;
@@ -214,8 +217,13 @@
   if (L->ci+1 == L->end_ci) {
     int size_ci = L->end_ci - L->base_ci;
     int index_ci = L->ci - L->base_ci;
-    L->base_ci = luaM_reallocvector(L->base_ci, size_ci * 2,
-				    struct CallInfo);
+    int 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);
+    free(L->base_ci);
+    L->base_ci = new_ci;
+    L->base_ci_size = new_ci_size;
     L->ci = L->base_ci + index_ci;
     L->end_ci = L->base_ci + size_ci * 2;
   }

Index: liolib.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/liolib.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- liolib.cpp	6 Oct 2004 19:07:53 -0000	1.1
+++ liolib.cpp	25 Dec 2004 18:23:07 -0000	1.2
@@ -442,6 +442,7 @@
 void lua_iolibopen (void)
 {
   luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0])));
+  luaL_addlibtolist(iolibtag, (sizeof(iolib)/sizeof(iolib[0])));
   openwithtags();
   lua_pushcfunction(errorfb);
   lua_seterrormethod();

Index: lmathlib.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lmathlib.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- lmathlib.cpp	6 Oct 2004 19:07:53 -0000	1.1
+++ lmathlib.cpp	25 Dec 2004 18:23:07 -0000	1.2
@@ -198,12 +198,17 @@
 {"randomseed", math_randomseed}
 };
 
+static luaL_reg powFunc[] = {
+{"math_pow",   math_pow}
+};
+
 /*
 ** Open math library
 */
 void lua_mathlibopen (void)
 {
   luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
+  luaL_addlibtolist(powFunc, (sizeof(powFunc)/sizeof(powFunc[0])));
   lua_pushstring("deg"); lua_setglobal("_TRIGMODE");
   lua_pushcfunction(math_pow);
   lua_pushnumber(0);  /* to get its tag */

Index: lstate.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lstate.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- lstate.cpp	6 Oct 2004 19:07:53 -0000	1.1
+++ lstate.cpp	25 Dec 2004 18:23:07 -0000	1.2
@@ -7,6 +7,7 @@
 
 #include "lbuiltin.h"
 #include "ldo.h"
+#include "lauxlib.h"
 #include "lfunc.h"
 #include "lgc.h"
 #include "llex.h"
@@ -14,11 +15,28 @@
 #include "lstate.h"
 #include "lstring.h"
 #include "ltable.h"
+#include "ltask.h"
 #include "ltm.h"
 
 
 lua_State *lua_state = NULL;
 
+void errorFB (void);
+void nilFB (void);
+void typeFB (void);
+
+static luaL_reg fbFuncs[] = {
+  {"  typeFB", typeFB},
+  {"  errorFB", errorFB},
+  {"  nilFB", nilFB}
+};
+
+void stderrorim (void);
+
+static luaL_reg stdErrorRimFunc[] = {
+  {"stderrorim", stderrorim}
+};
+
 static void lua_openthr (void)
 {
   L->numCblocks = 0;
@@ -33,10 +51,7 @@
   L->Tstate = RUN;
 }
 
-void lua_open (void)
-{
-  if (lua_state) return;
-  lua_state = luaM_new(lua_State);
+void lua_resetglobals(void) {
   lua_openthr();
   L->rootproto.next = NULL;
   L->rootproto.marked = 0;
@@ -58,11 +73,19 @@
   luaD_initthr();
   luaS_init();
   luaX_init();
+}
+
+void lua_open (void)
+{
+  if (lua_state) return;
+  lua_state = luaM_new(lua_State);
+  lua_resetglobals();
   luaT_init();
   luaB_predefine();
+  luaL_addlibtolist(stdErrorRimFunc, (sizeof(stdErrorRimFunc) / sizeof(stdErrorRimFunc[0])));
+  luaL_addlibtolist(fbFuncs, (sizeof(fbFuncs) / sizeof(fbFuncs[0])));
 }
 
-
 void lua_close (void)
 {
   TaggedString *alludata = luaS_collectudata();
@@ -101,12 +124,13 @@
   t->errorJmp = L->errorJmp;
   t->ci = L->ci;
   t->base_ci = L->base_ci;
+  t->base_ci_size = L->base_ci_size;
   t->end_ci = L->end_ci;
   t->Mbuffer = L->Mbuffer;
   t->Mbuffbase = L->Mbuffbase;
   t->Mbuffsize = L->Mbuffsize;
   t->Mbuffnext = L->Mbuffnext;
-  memcpy(t->Cblocks, L->Cblocks, sizeof(L->Cblocks));;
+  memcpy(t->Cblocks, L->Cblocks, sizeof(L->Cblocks));
   t->numCblocks = L->numCblocks;
   t->Tstate = L->Tstate;
 }
@@ -117,6 +141,7 @@
   L->errorJmp = t->errorJmp;
   L->ci = t->ci;
   L->base_ci = t->base_ci;
+  L->base_ci_size = t->base_ci_size;
   L->end_ci = t->end_ci;
   L->Mbuffer = t->Mbuffer;
   L->Mbuffbase = t->Mbuffbase;

Index: lstate.h
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lstate.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- lstate.h	6 Oct 2004 19:07:53 -0000	1.1
+++ lstate.h	25 Dec 2004 18:23:07 -0000	1.2
@@ -58,7 +58,7 @@
 };
 
 
-enum TaskState {RUN, YIELD, DONE};
+enum TaskState {RUN, YIELD, PAUSE, DONE};
 
 struct lua_Task {
   struct Stack stack;
@@ -66,6 +66,7 @@
   jmp_buf *errorJmp;
   struct CallInfo *ci;
   struct CallInfo *base_ci;
+  int base_ci_size;
   struct CallInfo *end_ci;
   char *Mbuffer;
   char *Mbuffbase;
@@ -85,6 +86,7 @@
   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;
   struct CallInfo *end_ci;  /* points after end of ci array */
   char *Mbuffer;  /* global buffer */
   char *Mbuffbase;  /* current first position of Mbuffer */
@@ -118,6 +120,7 @@
 
 #define L	lua_state
 
+void lua_resetglobals(void);
 
 /* Switch to the given task */
 void luaI_switchtask(struct lua_Task *t);

Index: lstring.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lstring.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- lstring.cpp	6 Oct 2004 19:07:53 -0000	1.1
+++ lstring.cpp	25 Dec 2004 18:23:07 -0000	1.2
@@ -14,14 +14,13 @@
 #include "lua.h"
 
 
-#define NUM_HASHS  61
 
 
 #define gcsizestring(l)	(1+(l/64))  /* "weight" for a string with length 'l' */
 
 
 
-static TaggedString EMPTY = {{NULL, 2}, 0L, 0,
+TaggedString EMPTY = {{NULL, 2}, 0L, 0,
                             {{{LUA_T_NIL, {NULL}}, 0L}}, {0}};
 
 

Index: lstring.h
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lstring.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- lstring.h	6 Oct 2004 19:07:53 -0000	1.1
+++ lstring.h	25 Dec 2004 18:23:07 -0000	1.2
@@ -24,5 +24,7 @@
 TaggedString *luaS_collectudata (void);
 void luaS_freeall (void);
 
+extern TaggedString EMPTY;
+#define NUM_HASHS  61
 
 #endif

Index: ltable.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/ltable.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ltable.cpp	6 Oct 2004 19:07:53 -0000	1.1
+++ ltable.cpp	25 Dec 2004 18:23:07 -0000	1.2
@@ -56,7 +56,7 @@
 }
 
 
-static int present (Hash *t, TObject *key)
+int present (Hash *t, TObject *key)
 {
   int tsize = nhash(t);
   long int h = hashindex(key);
@@ -77,7 +77,7 @@
 /*
 ** Alloc a vector node
 */
-static Node *hashnodecreate (int nhash)
+Node *hashnodecreate (int nhash)
 {
   Node *v = luaM_newvector(nhash, Node);
   int i;

Index: ltable.h
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/ltable.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ltable.h	6 Oct 2004 19:07:53 -0000	1.1
+++ ltable.h	25 Dec 2004 18:23:07 -0000	1.2
@@ -20,5 +20,7 @@
 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);
 
 #endif

Index: ltm.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/ltm.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ltm.cpp	6 Oct 2004 19:07:53 -0000	1.1
+++ ltm.cpp	25 Dec 2004 18:23:07 -0000	1.2
@@ -178,7 +178,7 @@
 
 #include "lapi.h"
 
-static void errorFB (void)
+void errorFB (void)
 {
   lua_Object o = lua_getparam(1);
   if (lua_isstring(o))
@@ -188,10 +188,10 @@
 }
 
 
-static void nilFB (void) { }
+void nilFB (void) { }
 
 
-static void typeFB (void)
+void typeFB (void)
 {
   lua_error("unexpected type");
 }

Index: lua.h
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lua.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- lua.h	6 Nov 2004 14:56:33 -0000	1.3
+++ lua.h	25 Dec 2004 18:23:07 -0000	1.4
@@ -26,6 +26,16 @@
 typedef struct lua_State lua_State;
 extern lua_State *lua_state;
 
+typedef int (*SaveRestoreCallback)(int, int, void (*)(void *, int));
+extern SaveRestoreCallback saveCallback;
+extern SaveRestoreCallback restoreCallback;
+
+typedef void (*SaveRestoreFunc)(void *, int);
+void lua_Save(SaveRestoreFunc);
+void lua_Restore(SaveRestoreFunc);
+
+void lua_removelibslists(void);
+
 void	       lua_open			(void);
 void           lua_close		(void);
 lua_State      *lua_setstate		(lua_State *st);





More information about the Scummvm-git-logs mailing list