static void continue_prepare(struct compile_and_run_frame *frame) { value closure; struct global_state *gcopy; if (mprepare_load_next_start(&frame->ps)) return; mprepare_vars(&frame->ps); gcopy = copy_global_state(frame->ps.ccontext->gstate); GCPRO1(gcopy); closure = compile_code(frame->ps.ccontext->gstate, frame->f->body); GCPOP(1); if (closure) { GCPRO1(closure); if (debug_lvl > 1) output_value(muderr, prt_examine, closure); frame->state = running; if (frame->dontrun) { /* Just leave the closure itself as the result */ stack_reserve(sizeof(value)); stack_push(closure); } else push_closure(closure, 0); GCPOP(1); return; } global_set(frame->ps.ccontext->gstate, gcopy); runtime_error(error_compile_error); }
void set_functions( lua_State* L, const lua_cpp::Reg * l, int nup ) { luaL_checkversion(L); luaL_checkstack(L, nup+1, "too many upvalues"); for (; l->name != NULL; l++) { /* fill the table with given functions */ int i; for (i = 0; i < nup; i++) /* copy upvalues to the top */ lua_pushvalue(L, -nup); push_closure(L, l->func, nup); /* closure with those upvalues */ lua_setfield(L, -(nup + 2), l->name); } lua_pop(L, nup); /* remove upvalues */ }
void set_functions( lua_State* L, const std::vector<lua_cpp::Reg>& functions, int nup ) { luaL_checkversion(L); luaL_checkstack(L, nup+1, "too many upvalues"); for (const lua_cpp::Reg& l : functions) { /* fill the table with given functions */ if (l.name == nullptr) { continue; } int i; for (i = 0; i < nup; ++i) /* copy upvalues to the top */ lua_pushvalue(L, -nup); push_closure(L, l.func, nup); /* closure with those upvalues */ lua_setfield(L, -(nup + 2), l.name); } lua_pop(L, nup); /* remove upvalues */ }