mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
new function mrb_closure_new_cfunc(); close #609
This commit is contained in:
+21
-4
@@ -26,15 +26,14 @@ mrb_proc_new(mrb_state *mrb, mrb_irep *irep)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RProc *
|
static void
|
||||||
mrb_closure_new(mrb_state *mrb, mrb_irep *irep)
|
closure_setup(mrb_state *mrb, struct RProc *p, int nlocals)
|
||||||
{
|
{
|
||||||
struct RProc *p = mrb_proc_new(mrb, irep);
|
|
||||||
struct REnv *e;
|
struct REnv *e;
|
||||||
|
|
||||||
if (!mrb->ci->env) {
|
if (!mrb->ci->env) {
|
||||||
e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, (struct RClass*)mrb->ci->proc->env);
|
e = (struct REnv*)mrb_obj_alloc(mrb, MRB_TT_ENV, (struct RClass*)mrb->ci->proc->env);
|
||||||
e->flags= (unsigned int)mrb->ci->proc->body.irep->nlocals;
|
e->flags= (unsigned int)nlocals;
|
||||||
e->mid = mrb->ci->mid;
|
e->mid = mrb->ci->mid;
|
||||||
e->cioff = mrb->ci - mrb->cibase;
|
e->cioff = mrb->ci - mrb->cibase;
|
||||||
e->stack = mrb->stack;
|
e->stack = mrb->stack;
|
||||||
@@ -47,6 +46,15 @@ mrb_closure_new(mrb_state *mrb, mrb_irep *irep)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct RProc *
|
||||||
|
mrb_closure_new(mrb_state *mrb, mrb_irep *irep)
|
||||||
|
{
|
||||||
|
struct RProc *p = mrb_proc_new(mrb, irep);
|
||||||
|
|
||||||
|
closure_setup(mrb, p, mrb->ci->proc->body.irep->nlocals);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
struct RProc *
|
struct RProc *
|
||||||
mrb_proc_new_cfunc(mrb_state *mrb, mrb_func_t func)
|
mrb_proc_new_cfunc(mrb_state *mrb, mrb_func_t func)
|
||||||
{
|
{
|
||||||
@@ -59,6 +67,15 @@ mrb_proc_new_cfunc(mrb_state *mrb, mrb_func_t func)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct RProc *
|
||||||
|
mrb_closure_new_cfunc(mrb_state *mrb, mrb_func_t func, int nlocals)
|
||||||
|
{
|
||||||
|
struct RProc *p = mrb_proc_new_cfunc(mrb, func);
|
||||||
|
|
||||||
|
closure_setup(mrb, p, nlocals);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mrb_proc_copy(struct RProc *a, struct RProc *b)
|
mrb_proc_copy(struct RProc *a, struct RProc *b)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user