Add user context pointer and flag argument to js_State constructor.

This commit is contained in:
Tor Andersson
2014-11-29 16:12:30 +01:00
parent 6538308087
commit 84faaff8ff
4 changed files with 17 additions and 3 deletions

1
jsi.h
View File

@@ -122,6 +122,7 @@ void js_savetry(js_State *J, js_Instruction *pc);
struct js_State
{
void *actx;
void *uctx;
js_Alloc alloc;
js_Panic panic;

View File

@@ -154,7 +154,17 @@ js_Panic js_atpanic(js_State *J, js_Panic panic)
return old;
}
js_State *js_newstate(js_Alloc alloc, void *actx)
void js_setcontext(js_State *J, void *uctx)
{
J->uctx = uctx;
}
void *js_getcontext(js_State *J)
{
return J->uctx;
}
js_State *js_newstate(js_Alloc alloc, void *actx, void *uctx, int flags)
{
js_State *J;
@@ -165,6 +175,7 @@ js_State *js_newstate(js_Alloc alloc, void *actx)
if (!J)
return NULL;
memset(J, 0, sizeof(*J));
J->uctx = uctx;
J->actx = actx;
J->alloc = alloc;

2
main.c
View File

@@ -117,7 +117,7 @@ main(int argc, char **argv)
js_State *J;
int i;
J = js_newstate(NULL, NULL);
J = js_newstate(NULL, NULL, NULL, 0);
js_newcfunction(J, jsB_gc, 0);
js_setglobal(J, "gc");

4
mujs.h
View File

@@ -31,7 +31,9 @@ typedef void (*js_Panic)(js_State *J);
typedef void (*js_CFunction)(js_State *J);
/* Basic functions */
js_State *js_newstate(js_Alloc alloc, void *actx);
js_State *js_newstate(js_Alloc alloc, void *actx, void *uctx, int flags);
void js_setcontext(js_State *J, void *uctx);
void *js_getcontext(js_State *J);
js_Panic js_atpanic(js_State *J, js_Panic panic);
void js_freestate(js_State *J);
void js_gc(js_State *J, int report);