mirror of
https://github.com/ccxvii/mujs.git
synced 2026-09-21 06:33:35 +08:00
Add functions to let C bindings define setters and getters.
Also add js_currentfunction to allow C bindings to access properties defined on the currently executing function.
This commit is contained in:
@@ -95,12 +95,14 @@ void js_getproperty(js_State *J, int idx, const char *name);
|
||||
void js_setproperty(js_State *J, int idx, const char *name);
|
||||
void js_defproperty(js_State *J, int idx, const char *name, int atts);
|
||||
void js_delproperty(js_State *J, int idx, const char *name);
|
||||
void js_defaccessor(js_State *J, int idx, const char *name);
|
||||
|
||||
int js_hasindex(js_State *J, int idx, unsigned int i);
|
||||
void js_getindex(js_State *J, int idx, unsigned int i);
|
||||
void js_setindex(js_State *J, int idx, unsigned int i);
|
||||
void js_delindex(js_State *J, int idx, unsigned int i);
|
||||
|
||||
void js_currentfunction(js_State *J);
|
||||
void js_pushglobal(js_State *J);
|
||||
void js_pushundefined(js_State *J);
|
||||
void js_pushnull(js_State *J);
|
||||
|
||||
@@ -108,6 +108,13 @@ void js_pushglobal(js_State *J)
|
||||
js_pushobject(J, J->G);
|
||||
}
|
||||
|
||||
void js_currentfunction(js_State *J)
|
||||
{
|
||||
CHECKSTACK(1);
|
||||
STACK[TOP] = STACK[BOT-1];
|
||||
++TOP;
|
||||
}
|
||||
|
||||
/* Read values from stack */
|
||||
|
||||
static const js_Value *stackidx(js_State *J, int idx)
|
||||
@@ -245,6 +252,8 @@ void *js_touserdata(js_State *J, const char *tag, int idx)
|
||||
static js_Object *jsR_tofunction(js_State *J, int idx)
|
||||
{
|
||||
const js_Value *v = stackidx(J, idx);
|
||||
if (v->type == JS_TNULL)
|
||||
return NULL;
|
||||
if (v->type == JS_TOBJECT)
|
||||
if (v->u.object->type == JS_CFUNCTION || v->u.object->type == JS_CCFUNCTION)
|
||||
return v->u.object;
|
||||
@@ -603,6 +612,12 @@ void js_delproperty(js_State *J, int idx, const char *name)
|
||||
jsR_delproperty(J, js_toobject(J, idx), name);
|
||||
}
|
||||
|
||||
void js_defaccessor(js_State *J, int idx, const char *name)
|
||||
{
|
||||
jsR_defproperty(J, js_toobject(J, idx), name, 0, NULL, jsR_tofunction(J, -2), jsR_tofunction(J, -1));
|
||||
js_pop(J, 2);
|
||||
}
|
||||
|
||||
int js_hasproperty(js_State *J, int idx, const char *name)
|
||||
{
|
||||
return jsR_hasproperty(J, js_toobject(J, idx), name);
|
||||
|
||||
Reference in New Issue
Block a user