From 84faaff8ff8d6e71bbd316edc633d90a38def6ec Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 29 Nov 2014 16:12:30 +0100 Subject: [PATCH] Add user context pointer and flag argument to js_State constructor. --- jsi.h | 1 + jsstate.c | 13 ++++++++++++- main.c | 2 +- mujs.h | 4 +++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/jsi.h b/jsi.h index f7cd03c..af54d4f 100644 --- a/jsi.h +++ b/jsi.h @@ -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; diff --git a/jsstate.c b/jsstate.c index d42d10b..7d30260 100644 --- a/jsstate.c +++ b/jsstate.c @@ -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; diff --git a/main.c b/main.c index 88226bb..6744bba 100644 --- a/main.c +++ b/main.c @@ -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"); diff --git a/mujs.h b/mujs.h index d11f926..97c6a3e 100644 --- a/mujs.h +++ b/mujs.h @@ -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);