[Scummvm-cvs-logs] CVS: residual/lua lbuiltin.cpp,1.5,1.6 lobject.cpp,1.1,1.2 lobject.h,1.1,1.2 lrestore.cpp,1.4,1.5 lsave.cpp,1.4,1.5 lstate.cpp,1.4,1.5 lstate.h,1.2,1.3 ltable.cpp,1.2,1.3 ltask.cpp,1.4,1.5 ltm.cpp,1.3,1.4
Pawel Kolodziejski
aquadran at users.sourceforge.net
Fri Jan 14 12:34:00 CET 2005
Update of /cvsroot/scummvm/residual/lua
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv683/residual/lua
Modified Files:
lbuiltin.cpp lobject.cpp lobject.h lrestore.cpp lsave.cpp
lstate.cpp lstate.h ltable.cpp ltask.cpp ltm.cpp
Log Message:
based on dissasembly changed task_tag into task object for proper save/restore and task identification and code realated
Index: lbuiltin.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lbuiltin.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- lbuiltin.cpp 12 Jan 2005 22:10:11 -0000 1.5
+++ lbuiltin.cpp 14 Jan 2005 20:33:01 -0000 1.6
@@ -168,6 +168,10 @@
sprintf(buff, "userdata: %p", o->value.ts->u.d.v);
break;
}
+ case LUA_T_TASK: {
+ sprintf(buff, "task: %d", (int)o->value.n);
+ break;
+ }
case LUA_T_NIL:
lua_pushstring("nil");
return;
@@ -522,21 +526,11 @@
#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");
luaL_openlib(int_funcs, (sizeof(int_funcs)/sizeof(int_funcs[0])));
lua_pushstring(LUA_VERSION);
lua_setglobal("_VERSION");
Index: lobject.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lobject.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- lobject.cpp 6 Oct 2004 19:07:53 -0000 1.1
+++ lobject.cpp 14 Jan 2005 20:33:01 -0000 1.2
@@ -11,7 +11,7 @@
char *luaO_typenames[] = { /* ORDER LUA_T */
- "userdata", "number", "string", "table", "function", "function",
+ "userdata", "number", "string", "table", "function", "function", "task",
"nil", "function", "mark", "mark", "mark", "line", NULL
};
@@ -50,6 +50,7 @@
case LUA_T_PROTO: return tfvalue(t1) == tfvalue(t2);
case LUA_T_CPROTO: return fvalue(t1) == fvalue(t2);
case LUA_T_CLOSURE: return t1->value.cl == t2->value.cl;
+ case LUA_T_TASK: return nvalue(t1) == nvalue(t2);
default:
LUA_INTERNALERROR("invalid type");
return 0; /* UNREACHABLE */
Index: lobject.h
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lobject.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- lobject.h 6 Oct 2004 19:07:53 -0000 1.1
+++ lobject.h 14 Jan 2005 20:33:01 -0000 1.2
@@ -67,16 +67,17 @@
LUA_T_ARRAY = -3, /* tag default for tables (or arrays) */
LUA_T_PROTO = -4, /* fixed tag for functions */
LUA_T_CPROTO = -5, /* fixed tag for Cfunctions */
- LUA_T_NIL = -6, /* last "pre-defined" tag */
- LUA_T_CLOSURE = -7,
- LUA_T_CLMARK = -8, /* mark for closures */
- LUA_T_PMARK = -9, /* mark for Lua prototypes */
- LUA_T_CMARK = -10, /* mark for C prototypes */
- LUA_T_LINE = -11
+ LUA_T_TASK = -6, /* task tag */
+ LUA_T_NIL = -7, /* last "pre-defined" tag */
+ LUA_T_CLOSURE = -8,
+ LUA_T_CLMARK = -9, /* mark for closures */
+ LUA_T_PMARK = -10, /* mark for Lua prototypes */
+ LUA_T_CMARK = -11, /* mark for C prototypes */
+ LUA_T_LINE = -12
} lua_Type;
-#define NUM_TYPES 11
-#define NUM_TAGS 7
+#define NUM_TYPES 12
+#define NUM_TAGS 8
typedef union {
Index: lrestore.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lrestore.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- lrestore.cpp 14 Jan 2005 10:51:20 -0000 1.4
+++ lrestore.cpp 14 Jan 2005 20:33:01 -0000 1.5
@@ -351,6 +351,8 @@
L->Mbuffbase = MbaseOffset + L->Mbuffer;
restoreFunc(&L->Mbuffnext, sizeof(int));
+ restoreFunc(&globalTaskSerialId, sizeof(int));
+
int countTasks;
lua_Task *tempTask = NULL;
restoreFunc(&countTasks, sizeof(int));
@@ -423,7 +425,7 @@
restoreFunc(&tempTask->Mbuffnext, sizeof(int));
restoreFunc(&tempTask->Tstate, sizeof(TaskState));
- restoreFunc(&tempTask->auto_delete, sizeof(int));
+ restoreFunc(&tempTask->id, sizeof(int));
}
L->last_task = tempTask;
Index: lsave.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lsave.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- lsave.cpp 14 Jan 2005 10:51:20 -0000 1.4
+++ lsave.cpp 14 Jan 2005 20:33:01 -0000 1.5
@@ -232,6 +232,8 @@
saveFunc(&MbaseOffset, sizeof(int));
saveFunc(&L->Mbuffnext, sizeof(int));
+ saveFunc(&globalTaskSerialId, sizeof(int));
+
int countTasks = 0;
lua_Task *tempTask = L->root_task->next;
while (tempTask != NULL) {
@@ -288,7 +290,7 @@
saveFunc(&tempTask->Mbuffnext, sizeof(int));
saveFunc(&tempTask->Tstate, sizeof(TaskState));
- saveFunc(&tempTask->auto_delete, sizeof(int));
+ saveFunc(&tempTask->id, sizeof(int));
tempTask = tempTask->next;
}
Index: lstate.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lstate.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- lstate.cpp 5 Jan 2005 00:30:37 -0000 1.4
+++ lstate.cpp 14 Jan 2005 20:33:01 -0000 1.5
@@ -22,6 +22,8 @@
lua_State *lua_state = NULL;
+int globalTaskSerialId;
+
void stderrorim (void);
static luaL_reg stdErrorRimFunc[] = {
@@ -43,6 +45,7 @@
}
void lua_resetglobals(void) {
+ globalTaskSerialId = 1;
lua_openthr();
L->rootproto.next = NULL;
L->rootproto.marked = 0;
@@ -155,8 +158,8 @@
result = luaM_new(struct lua_Task);
L->curr_task = result;
result->next = NULL;
- result->auto_delete = 0;
lua_openthr();
luaD_initthr();
+ result->id = globalTaskSerialId++;
return result;
}
Index: lstate.h
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/lstate.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- lstate.h 25 Dec 2004 18:23:07 -0000 1.2
+++ lstate.h 14 Jan 2005 20:33:01 -0000 1.3
@@ -76,7 +76,7 @@
int numCblocks;
enum TaskState Tstate;
struct lua_Task *next;
- int auto_delete; /* Set to 1 if no userdata references this task */
+ int id;
};
struct lua_State {
@@ -117,6 +117,7 @@
extern lua_State *lua_state;
+extern int globalTaskSerialId;
#define L lua_state
Index: ltable.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/ltable.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ltable.cpp 25 Dec 2004 18:23:07 -0000 1.2
+++ ltable.cpp 14 Jan 2005 20:33:01 -0000 1.3
@@ -48,6 +48,9 @@
case LUA_T_CLOSURE:
h = (IntPoint)clvalue(ref);
break;
+ case LUA_T_TASK:
+ h = (long int)nvalue(ref);
+ break;
default:
lua_error("unexpected type to index table");
h = 0; /* to avoid warnings */
Index: ltask.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/ltask.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ltask.cpp 22 Dec 2004 21:02:34 -0000 1.4
+++ ltask.cpp 14 Jan 2005 20:33:01 -0000 1.5
@@ -8,18 +8,27 @@
#include "ldo.h"
#include "lvm.h"
-int task_tag;
-
void pause_scripts (void) {
+ struct lua_Task *t;
+
+ for (t = L->root_task->next; t != NULL; t = t->next) {
+ if (t->Tstate != DONE)
+ t->Tstate = PAUSE;
+ }
}
void unpause_scripts (void) {
+ struct lua_Task *t;
+
+ for (t = L->root_task->next; t != NULL; t = t->next) {
+ if (t->Tstate == PAUSE)
+ t->Tstate = YIELD;
+ }
}
void start_script (void) {
struct lua_Task *old_task = L->curr_task, *new_task;
- TObject *f;
- int i;
+ TObject *f = L->stack.stack + L->Cstack.lua2C;
f = L->stack.stack + L->Cstack.lua2C;
if (ttype(f) == LUA_T_CLOSURE)
@@ -31,7 +40,7 @@
new_task = luaI_newtask();
/* Put the function and arguments onto the new task's stack */
- for (i = 0; i < old_task->Cstack.num; i++) {
+ for (int i = 0; i < old_task->Cstack.num; i++) {
*(L->stack.top) = *(old_task->stack.stack + old_task->Cstack.lua2C + i);
incr_top;
}
@@ -50,7 +59,9 @@
L->last_task = new_task;
/* Return task handle */
- lua_pushusertag(new_task, task_tag);
+ ttype(L->stack.top) = LUA_T_TASK;
+ nvalue(L->stack.top) = new_task->id;
+ incr_top;
}
void stop_script (void) {
@@ -58,7 +69,7 @@
TObject *f = L->stack.stack + L->Cstack.lua2C;
int match;
- if (ttype(f) != LUA_T_CLOSURE && ttype(f) != LUA_T_PROTO && !(ttype(f) == LUA_T_USERDATA && f->value.ts->u.d.tag == task_tag))
+ 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");
prev = L->root_task;
@@ -70,8 +81,8 @@
case LUA_T_PROTO:
match = (ttype(t->stack.stack) == LUA_T_PMARK && tfvalue(t->stack.stack) == tfvalue(f));
break;
- case LUA_T_USERDATA:
- match = (t == f->value.ts->u.d.v);
+ case LUA_T_TASK:
+ match = (t->id == (int)nvalue(f));
break;
default: /* Shut up gcc */
break;
@@ -87,9 +98,6 @@
}
} else {
t->Tstate = DONE;
- if (t->auto_delete) {
- luaM_free(t);
- }
}
} else {
prev = t;
@@ -98,76 +106,108 @@
}
void next_script (void) {
- struct lua_Task *t;
+ struct lua_Task *t, *prev;
+ TObject *f = L->stack.stack + L->Cstack.lua2C;
- if (lua_isnil(lua_getparam(1))) {
+ if (f == LUA_NOOBJECT)
+ lua_error("Bad argument to next_script: no obeject");
+
+ prev = L->root_task;
+ if (ttype(f) == LUA_T_NIL) {
t = L->root_task;
- } else if (lua_isuserdata(lua_getparam(1)) && lua_tag(lua_getparam(1)) == task_tag) {
- t = (struct lua_Task *) lua_getuserdata(lua_getparam(1));
+ } else if (ttype(f) == LUA_T_TASK) {
+ int taskId = (int)nvalue(f);
+ for (t = L->root_task->next; t != NULL; t = t->next) {
+ if (t->id == taskId)
+ break;
+ }
} else {
- lua_error("Bad argument to next_script");
+ lua_error("Bad argument to next_script.");
}
- t = t->next;
if (t == NULL) {
lua_pushnil();
} else {
- t->auto_delete = 0;
- lua_pushusertag(t, task_tag);
+ t = t->next;
+ if (t == NULL) {
+ lua_pushnil();
+ } else {
+ ttype(L->stack.top) = LUA_T_TASK;
+ nvalue(L->stack.top) = t->id;
+ incr_top;
+ }
}
}
void identify_script (void) {
struct lua_Task *t;
+ TObject *f = L->stack.stack + L->Cstack.lua2C;
- if (! lua_isuserdata(lua_getparam(1)) || lua_tag(lua_getparam(1)) != task_tag) {
+ if ((f == LUA_NOOBJECT) || ttype(f) != LUA_T_TASK) {
lua_error("Bad argument to identify_script");
}
- t = (struct lua_Task *) lua_getuserdata(lua_getparam(1));
- if (t->Tstate == DONE) {
- ttype(L->stack.top) = LUA_T_NIL;
- } else {
- *L->stack.top = *t->stack.stack;
- }
- incr_top;
+
+ int taskId = (int)nvalue(f);
+ for (t = L->root_task->next; t != NULL; t = t->next) {
+ if (t->id == taskId)
+ break;
+ }
+
+ if ((t == NULL) || (t->Tstate == DONE)) {
+ ttype(L->stack.top) = LUA_T_NIL;
+ } else {
+ *L->stack.top = *t->stack.stack;
+ }
+ incr_top;
}
void find_script (void) {
- struct lua_Task *t;
+ struct lua_Task *t, *foundTask = NULL;
TObject *f = L->stack.stack + L->Cstack.lua2C;
+ int countTasks = 0, taskId;
switch (ttype(f)) {
case LUA_T_CLOSURE:
for (t = L->root_task->next; t != NULL; t = t->next) {
- if ((ttype(t->stack.stack) == LUA_T_CLOSURE || ttype(t->stack.stack) == LUA_T_CMARK) && clvalue(t->stack.stack) == clvalue(f))
- break;
+ if ((ttype(t->stack.stack) == LUA_T_CLOSURE || ttype(t->stack.stack) == LUA_T_CMARK) && clvalue(t->stack.stack) == clvalue(f)) {
+ foundTask = t;
+ countTasks++;
+ }
}
+ t = foundTask;
break;
case LUA_T_PROTO:
for (t = L->root_task->next; t != NULL; t = t->next) {
- if ((ttype(t->stack.stack) == LUA_T_PROTO || ttype(t->stack.stack) == LUA_T_PMARK) && tfvalue(t->stack.stack) == tfvalue(f))
- break;
- }
- break;
- case LUA_T_USERDATA:
- if (f->value.ts->u.d.tag != task_tag) {
- lua_error("Bad argument to find_script");
+ if ((ttype(t->stack.stack) == LUA_T_PROTO || ttype(t->stack.stack) == LUA_T_PMARK) && tfvalue(t->stack.stack) == tfvalue(f)) {
+ foundTask = t;
+ countTasks++;
+ }
}
- /* Shortcut: just see whether it's still running */
- t = (lua_Task *)f->value.ts->u.d.v;
- if (t->Tstate == DONE) {
- lua_pushnil();
- } else {
- lua_pushusertag(t, task_tag);
+ t = foundTask;
+ break;
+ case LUA_T_TASK:
+ taskId = (int)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;
+ nvalue(L->stack.top) = nvalue(f);
+ incr_top;
+ lua_pushnumber(1.0f);
+ return;
+ }
}
- return;
+ break;
default:
lua_error("Bad argument to find_script");
}
- if (t == NULL) {
- lua_pushnil();
+
+ if (t != NULL) {
+ ttype(L->stack.top) = LUA_T_TASK;
+ nvalue(L->stack.top) = t->id;
+ incr_top;
+ lua_pushnumber(countTasks);
} else {
- t->auto_delete = 0;
- lua_pushusertag(t, task_tag);
+ lua_pushnil();
+ lua_pushnumber(0.0f);
}
}
@@ -189,8 +229,9 @@
if (L->curr_task == L->root_task) {
lua_pushnil();
} else {
- L->curr_task->auto_delete = 0;
- lua_pushusertag(L->curr_task, task_tag);
+ ttype(L->stack.top) = LUA_T_TASK;
+ nvalue(L->stack.top) = L->curr_task->id;
+ incr_top;
}
}
@@ -201,6 +242,8 @@
prev = L->root_task;
while ((t = prev->next) != NULL) {
+ if (t->Tstate == PAUSE)
+ continue;
luaI_switchtask(t);
L->errorJmp = &myErrorJmp;
L->Tstate = RUN;
@@ -220,9 +263,7 @@
if (prev->next == NULL) {
L->last_task = prev;
}
- if (t->auto_delete) {
- luaM_free(t);
- }
+ luaM_free(t);
} else {
prev = t;
}
@@ -231,12 +272,3 @@
luaI_switchtask(old_task);
}
}
-
-void gc_task (void) {
- struct lua_Task *t = (struct lua_Task *) lua_getuserdata(lua_getparam(1));
-
- t->auto_delete = 1;
- if (t != L->curr_task && t->Tstate == DONE) {
- luaM_free(t);
- }
-}
Index: ltm.cpp
===================================================================
RCS file: /cvsroot/scummvm/residual/lua/ltm.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ltm.cpp 30 Dec 2004 07:37:13 -0000 1.3
+++ ltm.cpp 14 Jan 2005 20:33:01 -0000 1.4
@@ -43,6 +43,7 @@
{0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_ARRAY */
{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_PROTO */
{1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, /* LUA_T_CPROTO */
+{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* LUA_T_TASK */
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} /* LUA_T_NIL */
};
More information about the Scummvm-git-logs
mailing list