public static void LuaDCallHook(LuaState L, int event_, int line) { LuaHook hook = L.hook; if ((hook != null) && (L.allowhook != 0)) { ptrdiff_t top = SaveStack(L, L.top); ptrdiff_t ci_top = SaveStack(L, L.ci.top); LuaDebug ar = new LuaDebug(); ar.event_ = event_; ar.currentline = line; if (event_ == LUA_HOOKTAILRET) ar.i_ci = 0; /* tail call; no debug information about it */ else ar.i_ci = L.ci - L.base_ci; LuaDCheckStack(L, LUA_MINSTACK); /* ensure minimum stack size */ L.ci.top = L.top + LUA_MINSTACK; LuaAssert(L.ci.top <= L.stack_last); L.allowhook = 0; /* cannot call hooks inside a hook */ LuaUnlock(L); hook(L, ar); LuaLock(L); LuaAssert(L.allowhook == 0); L.allowhook = 1; L.ci.top = RestoreStack(L, ci_top); L.top = RestoreStack(L, top); } }
public static void LuaDCallHook(LuaState L, int event_, int line) { LuaHook hook = L.hook; if ((hook != null) && (L.allowhook != 0)) { ptrdiff_t top = SaveStack(L, L.top); ptrdiff_t ci_top = SaveStack(L, L.ci.top); LuaDebug ar = new LuaDebug(); ar.event_ = event_; ar.currentline = line; if (event_ == LUA_HOOKTAILRET) { ar.i_ci = 0; /* tail call; no debug information about it */ } else { ar.i_ci = L.ci - L.base_ci; } LuaDCheckStack(L, LUA_MINSTACK); /* ensure minimum stack size */ L.ci.top = L.top + LUA_MINSTACK; LuaAssert(L.ci.top <= L.stack_last); L.allowhook = 0; /* cannot call hooks inside a hook */ LuaUnlock(L); hook(L, ar); LuaLock(L); LuaAssert(L.allowhook == 0); L.allowhook = 1; L.ci.top = RestoreStack(L, ci_top); L.top = RestoreStack(L, top); } }
public static int LuaGetStack(LuaState L, int level, ref LuaDebug ar) { int status; CallInfo ci; LuaLock(L); for (ci = L.ci; level > 0 && ci > L.base_ci[0]; CallInfo.Dec(ref ci)) { level--; if (FIsLua(ci)) /* Lua function? */ { level -= ci.tailcalls; /* skip lost tail calls */ } } if (level == 0 && ci > L.base_ci[0]) /* level found? */ { status = 1; ar.i_ci = ci - L.base_ci[0]; } else if (level < 0) /* level is of a lost tail call? */ { status = 1; ar.i_ci = 0; } else { status = 0; /* no such level */ } LuaUnlock(L); return(status); }
private static int costatus(LuaState L, LuaState co) { if (L == co) { return(CO_RUN); } switch (LuaStatus(co)) { case LUA_YIELD: return(CO_SUS); case 0: { LuaDebug ar = new LuaDebug(); if (LuaGetStack(co, 0, ar) > 0) /* does it have frames? */ { return(CO_NOR); /* it is running */ } else if (LuaGetTop(co) == 0) { return(CO_DEAD); } else { return(CO_SUS); /* initial state */ } } default: /* some error occured */ return(CO_DEAD); } }
private static int DBGetLocal(LuaState L) { int arg; LuaState L1 = GetThread(L, out arg); LuaDebug ar = new LuaDebug(); CharPtr name; if (LuaGetStack(L1, LuaLCheckInt(L, arg + 1), ar) == 0) /* out of range? */ { return(LuaLArgError(L, arg + 1, "level out of range")); } name = LuaGetLocal(L1, ar, LuaLCheckInt(L, arg + 2)); if (name != null) { LuaXMove(L1, L, 1); LuaPushString(L, name); LuaPushValue(L, -2); return(2); } else { LuaPushNil(L); return(1); } }
/* ** {====================================================== ** Error-report functions ** ======================================================= */ public static int LuaLArgError(LuaState L, int narg, CharPtr extramsg) { LuaDebug ar = new LuaDebug(); if (LuaGetStack(L, 0, ref ar) == 0) /* no stack frame? */ { return(LuaLError(L, "bad argument #%d (%s)", narg, extramsg)); } LuaGetInfo(L, "n", ref ar); if (strcmp(ar.namewhat, "method") == 0) { narg--; /* do not count `self' */ if (narg == 0) /* error is in the self argument itself? */ { return(LuaLError(L, "calling " + LUA_QS + " on bad self ({1})", ar.name, extramsg)); } } if (ar.name == null) { ar.name = "?"; } return(LuaLError(L, "bad argument #%d to " + LUA_QS + " (%s)", narg, ar.name, extramsg)); }
private static void InfoTailCall(LuaDebug ar) { ar.name = ar.namewhat = ""; ar.what = "tail"; ar.lastlinedefined = ar.linedefined = ar.currentline = -1; ar.source = "=(tail call)"; LuaOChunkID(ar.short_src, ar.source, LUA_IDSIZE); ar.nups = 0; }
public static CharPtr LuaGetLocal(LuaState L, LuaDebug ar, int n) { CallInfo ci = L.base_ci[ar.i_ci]; CharPtr name = FindLocal(L, ci, n); LuaLock(L); if (name != null) { LuaAPushObject(L, ci.base_[n - 1]); } LuaUnlock(L); return(name); }
public static CharPtr LuaSetLocal(LuaState L, LuaDebug ar, int n) { CallInfo ci = L.base_ci[ar.i_ci]; CharPtr name = FindLocal(L, ci, n); LuaLock(L); if (name != null) { SetObj2S(L, ci.base_[n - 1], L.top - 1); } StkId.Dec(ref L.top); /* pop value */ LuaUnlock(L); return(name); }
public static void LuaLWhere(LuaState L, int level) { LuaDebug ar = new LuaDebug(); if (LuaGetStack(L, level, ref ar) != 0) /* check function at level */ { LuaGetInfo(L, "Sl", ref ar); /* get info about it */ if (ar.currentline > 0) /* is there info? */ { LuaPushFString(L, "%s:%d: ", ar.short_src, ar.currentline); return; } } LuaPushLiteral(L, ""); /* else, no information available... */ }
private static int AuxGetInfo(LuaState L, CharPtr what, LuaDebug ar, Closure f, CallInfo ci) { int status = 1; if (f == null) { InfoTailCall(ar); return(status); } for (; what[0] != 0; what = what.next()) { switch (what[0]) { case 'S': { FuncInfo(ar, f); break; } case 'l': { ar.currentline = (ci != null) ? CurrentLine(L, ci) : -1; break; } case 'u': { ar.nups = f.c.nupvalues; break; } case 'n': { ar.namewhat = (ci != null) ? GetFuncName(L, ci, ref ar.name) : null; if (ar.namewhat == null) { ar.namewhat = ""; /* not found */ ar.name = null; } break; } case 'L': case 'f': /* handled by lua_getinfo */ break; default: status = 0; break; /* invalid option */ } } return(status); }
private static int DBSetLocal(LuaState L) { int arg; LuaState L1 = GetThread(L, out arg); LuaDebug ar = new LuaDebug(); if (LuaGetStack(L1, LuaLCheckInt(L, arg + 1), ar) == 0) /* out of range? */ { return(LuaLArgError(L, arg + 1, "level out of range")); } LuaLCheckAny(L, arg + 3); LuaSetTop(L, arg + 3); LuaXMove(L, L1, 1); LuaPushString(L, LuaSetLocal(L1, ar, LuaLCheckInt(L, arg + 2))); return(1); }
private static void FuncInfo(LuaDebug ar, Closure cl) { if (cl.c.isC != 0) { ar.source = "=[C]"; ar.linedefined = -1; ar.lastlinedefined = -1; ar.what = "C"; } else { ar.source = GetStr(cl.l.p.source); ar.linedefined = cl.l.p.linedefined; ar.lastlinedefined = cl.l.p.lastlinedefined; ar.what = (ar.linedefined == 0) ? "main" : "Lua"; } LuaOChunkID(ar.short_src, ar.source, LUA_IDSIZE); }
public static int LuaGetInfo(LuaState L, CharPtr what, ref LuaDebug ar) { int status; Closure f = null; CallInfo ci = null; LuaLock(L); if (what == '>') { StkId func = L.top - 1; luai_apicheck(L, TTIsFunction(func)); what = what.next(); /* skip the '>' */ f = CLValue(func); StkId.Dec(ref L.top); /* pop function */ } else if (ar.i_ci != 0) /* no tail call? */ { ci = L.base_ci[ar.i_ci]; LuaAssert(TTIsFunction(ci.func)); f = CLValue(ci.func); } status = AuxGetInfo(L, what, ar, f, ci); if (strchr(what, 'f') != null) { if (f == null) { SetNilValue(L.top); } else { SetCLValue(L, L.top, f); } IncrTop(L); } if (strchr(what, 'L') != null) { CollectValidLines(L, f); } LuaUnlock(L); return(status); }
private static void HookF(LuaState L, LuaDebug ar) { LuaPushLightUserData(L, KEY_HOOK); LuaRawGet(L, LUA_REGISTRYINDEX); LuaPushLightUserData(L, L); LuaRawGet(L, -2); if (LuaIsFunction(L, -1)) { LuaPushString(L, hooknames[(int)ar.event_]); if (ar.currentline >= 0) { LuaPushInteger(L, ar.currentline); } else { LuaPushNil(L); } LuaAssert(LuaGetInfo(L, "lS", ar)); LuaCall(L, 2, 0); } }
public static int LuaGetStack (LuaState L, int level, ref LuaDebug ar) { int status; CallInfo ci; LuaLock(L); for (ci = L.ci; level > 0 && ci > L.base_ci[0]; CallInfo.Dec(ref ci)) { level--; if (FIsLua(ci)) /* Lua function? */ level -= ci.tailcalls; /* skip lost tail calls */ } if (level == 0 && ci > L.base_ci[0]) { /* level found? */ status = 1; ar.i_ci = ci - L.base_ci[0]; } else if (level < 0) { /* level is of a lost tail call? */ status = 1; ar.i_ci = 0; } else status = 0; /* no such level */ LuaUnlock(L); return status; }
private static void GetFunc(LuaState L, int opt) { if (LuaIsFunction(L, 1)) { LuaPushValue(L, 1); } else { LuaDebug ar = new LuaDebug(); int level = (opt != 0) ? LuaLOptInt(L, 1, 1) : LuaLCheckInt(L, 1); LuaLArgCheck(L, level >= 0, 1, "level must be non-negative"); if (LuaGetStack(L, level, ar) == 0) { LuaLArgError(L, 1, "invalid level"); } LuaGetInfo(L, "f", ar); if (LuaIsNil(L, -1)) { LuaLError(L, "no function environment for tail call at level %d", level); } } }
public static int LuaGetInfo (LuaState L, CharPtr what, ref LuaDebug ar) { int status; Closure f = null; CallInfo ci = null; LuaLock(L); if (what == '>') { StkId func = L.top - 1; luai_apicheck(L, TTIsFunction(func)); what = what.next(); /* skip the '>' */ f = CLValue(func); StkId.Dec(ref L.top); /* pop function */ } else if (ar.i_ci != 0) { /* no tail call? */ ci = L.base_ci[ar.i_ci]; LuaAssert(TTIsFunction(ci.func)); f = CLValue(ci.func); } status = AuxGetInfo(L, what, ar, f, ci); if (strchr(what, 'f') != null) { if (f == null) SetNilValue(L.top); else SetCLValue(L, L.top, f); IncrTop(L); } if (strchr(what, 'L') != null) CollectValidLines(L, f); LuaUnlock(L); return status; }
private static int AuxGetInfo (LuaState L, CharPtr what, LuaDebug ar, Closure f, CallInfo ci) { int status = 1; if (f == null) { InfoTailCall(ar); return status; } for (; what[0] != 0; what = what.next()) { switch (what[0]) { case 'S': { FuncInfo(ar, f); break; } case 'l': { ar.currentline = (ci != null) ? CurrentLine(L, ci) : -1; break; } case 'u': { ar.nups = f.c.nupvalues; break; } case 'n': { ar.namewhat = (ci!=null) ? GetFuncName(L, ci, ref ar.name) : null; if (ar.namewhat == null) { ar.namewhat = ""; /* not found */ ar.name = null; } break; } case 'L': case 'f': /* handled by lua_getinfo */ break; default: status = 0; break;/* invalid option */ } } return status; }
private static void InfoTailCall (LuaDebug ar) { ar.name = ar.namewhat = ""; ar.what = "tail"; ar.lastlinedefined = ar.linedefined = ar.currentline = -1; ar.source = "=(tail call)"; LuaOChunkID(ar.short_src, ar.source, LUA_IDSIZE); ar.nups = 0; }
private static void FuncInfo (LuaDebug ar, Closure cl) { if (cl.c.isC != 0) { ar.source = "=[C]"; ar.linedefined = -1; ar.lastlinedefined = -1; ar.what = "C"; } else { ar.source = GetStr(cl.l.p.source); ar.linedefined = cl.l.p.linedefined; ar.lastlinedefined = cl.l.p.lastlinedefined; ar.what = (ar.linedefined == 0) ? "main" : "Lua"; } LuaOChunkID(ar.short_src, ar.source, LUA_IDSIZE); }
public static void LuaLWhere (LuaState L, int level) { LuaDebug ar = new LuaDebug(); if (LuaGetStack(L, level, ref ar) != 0) { /* check function at level */ LuaGetInfo(L, "Sl", ref ar); /* get info about it */ if (ar.currentline > 0) { /* is there info? */ LuaPushFString(L, "%s:%d: ", ar.short_src, ar.currentline); return; } } LuaPushLiteral(L, ""); /* else, no information available... */ }
private static int DBGetInfo(LuaState L) { LuaDebug ar = new LuaDebug(); int arg; LuaState L1 = GetThread(L, out arg); CharPtr options = LuaLOptString(L, arg + 2, "flnSu"); if (LuaIsNumber(L, arg + 1) != 0) { if (LuaGetStack(L1, (int)LuaToInteger(L, arg + 1), ar) == 0) { LuaPushNil(L); /* level out of range */ return(1); } } else if (LuaIsFunction(L, arg + 1)) { LuaPushFString(L, ">%s", options); options = LuaToString(L, -1); LuaPushValue(L, arg + 1); LuaXMove(L, L1, 1); } else { return(LuaLArgError(L, arg + 1, "function or level expected")); } if (LuaGetInfo(L1, options, ar) == 0) { return(LuaLArgError(L, arg + 2, "invalid option")); } LuaCreateTable(L, 0, 2); if (strchr(options, 'S') != null) { SetTabsS(L, "source", ar.source); SetTabsS(L, "short_src", ar.short_src); SetTabSI(L, "linedefined", ar.linedefined); SetTabSI(L, "lastlinedefined", ar.lastlinedefined); SetTabsS(L, "what", ar.what); } if (strchr(options, 'l') != null) { SetTabSI(L, "currentline", ar.currentline); } if (strchr(options, 'u') != null) { SetTabSI(L, "nups", ar.nups); } if (strchr(options, 'n') != null) { SetTabsS(L, "name", ar.name); SetTabsS(L, "namewhat", ar.namewhat); } if (strchr(options, 'L') != null) { TreatStackOption(L, L1, "activelines"); } if (strchr(options, 'f') != null) { TreatStackOption(L, L1, "func"); } return(1); /* return table */ }
public const int LEVELS2 = 10; /* size of the second part of the stack */ private static int DBErrorFB(LuaState L) { int level; bool firstpart = true; /* still before eventual `...' */ int arg; LuaState L1 = GetThread(L, out arg); LuaDebug ar = new LuaDebug(); if (LuaIsNumber(L, arg + 2) != 0) { level = (int)LuaToInteger(L, arg + 2); LuaPop(L, 1); } else { level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ } if (LuaGetTop(L) == arg) { LuaPushLiteral(L, ""); } else if (LuaIsString(L, arg + 1) == 0) { return(1); /* message is not a string */ } else { LuaPushLiteral(L, "\n"); } LuaPushLiteral(L, "stack traceback:"); while (LuaGetStack(L1, level++, ar) != 0) { if (level > LEVELS1 && firstpart) { /* no more than `LEVELS2' more levels? */ if (LuaGetStack(L1, level + LEVELS2, ar) == 0) { level--; /* keep going */ } else { LuaPushLiteral(L, "\n\t..."); /* too many levels */ while (LuaGetStack(L1, level + LEVELS2, ar) != 0) /* find last levels */ { level++; } } firstpart = false; continue; } LuaPushLiteral(L, "\n\t"); LuaGetInfo(L1, "Snl", ar); LuaPushFString(L, "%s:", ar.short_src); if (ar.currentline > 0) { LuaPushFString(L, "%d:", ar.currentline); } if (ar.namewhat != '\0') /* is there a name? */ { LuaPushFString(L, " in function " + LUA_QS, ar.name); } else { if (ar.what == 'm') /* main? */ { LuaPushFString(L, " in main chunk"); } else if (ar.what == 'C' || ar.what == 't') { LuaPushLiteral(L, " ?"); /* C function or tail call */ } else { LuaPushFString(L, " in function <%s:%d>", ar.short_src, ar.linedefined); } } LuaConcat(L, LuaGetTop(L) - arg); } LuaConcat(L, LuaGetTop(L) - arg); return(1); }
private static int DBErrorFB(LuaState L) { int level; bool firstpart = true; /* still before eventual `...' */ int arg; LuaState L1 = GetThread(L, out arg); LuaDebug ar = new LuaDebug(); if (LuaIsNumber(L, arg+2) != 0) { level = (int)LuaToInteger(L, arg+2); LuaPop(L, 1); } else level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ if (LuaGetTop(L) == arg) LuaPushLiteral(L, ""); else if (LuaIsString(L, arg+1)==0) return 1; /* message is not a string */ else LuaPushLiteral(L, "\n"); LuaPushLiteral(L, "stack traceback:"); while (LuaGetStack(L1, level++, ar) != 0) { if (level > LEVELS1 && firstpart) { /* no more than `LEVELS2' more levels? */ if (LuaGetStack(L1, level+LEVELS2, ar)==0) level--; /* keep going */ else { LuaPushLiteral(L, "\n\t..."); /* too many levels */ while (LuaGetStack(L1, level+LEVELS2, ar) != 0) /* find last levels */ level++; } firstpart = false; continue; } LuaPushLiteral(L, "\n\t"); LuaGetInfo(L1, "Snl", ar); LuaPushFString(L, "%s:", ar.short_src); if (ar.currentline > 0) LuaPushFString(L, "%d:", ar.currentline); if (ar.namewhat != '\0') /* is there a name? */ LuaPushFString(L, " in function " + LUA_QS, ar.name); else { if (ar.what == 'm') /* main? */ LuaPushFString(L, " in main chunk"); else if (ar.what == 'C' || ar.what == 't') LuaPushLiteral(L, " ?"); /* C function or tail call */ else LuaPushFString(L, " in function <%s:%d>", ar.short_src, ar.linedefined); } LuaConcat(L, LuaGetTop(L) - arg); } LuaConcat(L, LuaGetTop(L) - arg); return 1; }
private static int costatus(LuaState L, LuaState co) { if (L == co) return CO_RUN; switch (LuaStatus(co)) { case LUA_YIELD: return CO_SUS; case 0: { LuaDebug ar = new LuaDebug(); if (LuaGetStack(co, 0,ref ar) > 0) /* does it have frames? */ return CO_NOR; /* it is running */ else if (LuaGetTop(co) == 0) return CO_DEAD; else return CO_SUS; /* initial state */ } default: /* some error occured */ return CO_DEAD; } }
static void lstop(LuaState L, LuaDebug ar) { Lua.LuaSetHook(L, null, 0, 0); Lua.LuaLError(L, "interrupted!"); }
private static void GetFunc(LuaState L, int opt) { if (LuaIsFunction(L, 1)) LuaPushValue(L, 1); else { LuaDebug ar = new LuaDebug(); int level = (opt != 0) ? LuaLOptInt(L, 1, 1) : LuaLCheckInt(L, 1); LuaLArgCheck(L, level >= 0, 1, "level must be non-negative"); if (LuaGetStack(L, level, ref ar) == 0) LuaLArgError(L, 1, "invalid level"); LuaGetInfo(L, "f", ref ar); if (LuaIsNil(L, -1)) LuaLError(L, "no function environment for tail call at level %d", level); } }
private static int DBGetInfo(LuaState L) { LuaDebug ar = new LuaDebug(); int arg; LuaState L1 = GetThread(L, out arg); CharPtr options = LuaLOptString(L, arg+2, "flnSu"); if (LuaIsNumber(L, arg+1) != 0) { if (LuaGetStack(L1, (int)LuaToInteger(L, arg+1), ar)==0) { LuaPushNil(L); /* level out of range */ return 1; } } else if (LuaIsFunction(L, arg+1)) { LuaPushFString(L, ">%s", options); options = LuaToString(L, -1); LuaPushValue(L, arg+1); LuaXMove(L, L1, 1); } else return LuaLArgError(L, arg+1, "function or level expected"); if (LuaGetInfo(L1, options, ar)==0) return LuaLArgError(L, arg+2, "invalid option"); LuaCreateTable(L, 0, 2); if (strchr(options, 'S') != null) { SetTabsS(L, "source", ar.source); SetTabsS(L, "short_src", ar.short_src); SetTabSI(L, "linedefined", ar.linedefined); SetTabSI(L, "lastlinedefined", ar.lastlinedefined); SetTabsS(L, "what", ar.what); } if (strchr(options, 'l') != null) SetTabSI(L, "currentline", ar.currentline); if (strchr(options, 'u') != null) SetTabSI(L, "nups", ar.nups); if (strchr(options, 'n') != null) { SetTabsS(L, "name", ar.name); SetTabsS(L, "namewhat", ar.namewhat); } if (strchr(options, 'L') != null) TreatStackOption(L, L1, "activelines"); if (strchr(options, 'f') != null) TreatStackOption(L, L1, "func"); return 1; /* return table */ }
public DebugHookEventArgs(LuaDebug luaDebug) { this.luaDebug = luaDebug; }
private static int DBSetLocal(LuaState L) { int arg; LuaState L1 = GetThread(L, out arg); LuaDebug ar = new LuaDebug(); if (LuaGetStack(L1, LuaLCheckInt(L, arg+1), ar)==0) /* out of range? */ return LuaLArgError(L, arg+1, "level out of range"); LuaLCheckAny(L, arg+3); LuaSetTop(L, arg+3); LuaXMove(L, L1, 1); LuaPushString(L, LuaSetLocal(L1, ar, LuaLCheckInt(L, arg+2))); return 1; }
private static void HookF(LuaState L, LuaDebug ar) { LuaPushLightUserData(L, KEY_HOOK); LuaRawGet(L, LUA_REGISTRYINDEX); LuaPushLightUserData(L, L); LuaRawGet(L, -2); if (LuaIsFunction(L, -1)) { LuaPushString(L, hooknames[(int)ar.event_]); if (ar.currentline >= 0) LuaPushInteger(L, ar.currentline); else LuaPushNil(L); LuaAssert(LuaGetInfo(L, "lS", ar)); LuaCall(L, 2, 0); } }
public static CharPtr LuaSetLocal (LuaState L, LuaDebug ar, int n) { CallInfo ci = L.base_ci[ar.i_ci]; CharPtr name = FindLocal(L, ci, n); LuaLock(L); if (name != null) SetObj2S(L, ci.base_[n - 1], L.top-1); StkId.Dec(ref L.top); /* pop value */ LuaUnlock(L); return name; }
private static void DebugHookCallback(LuaState luaState, LuaDebug luaDebug) { var translator = ObjectTranslatorPool.Instance.Find(luaState); var lua = translator.Interpreter; lua.DebugHookCallbackInternal(luaState, luaDebug); }
/* ** {====================================================== ** Error-report functions ** ======================================================= */ public static int LuaLArgError (LuaState L, int narg, CharPtr extramsg) { LuaDebug ar = new LuaDebug(); if (LuaGetStack(L, 0, ref ar)==0) /* no stack frame? */ return LuaLError(L, "bad argument #%d (%s)", narg, extramsg); LuaGetInfo(L, "n", ref ar); if (strcmp(ar.namewhat, "method") == 0) { narg--; /* do not count `self' */ if (narg == 0) /* error is in the self argument itself? */ return LuaLError(L, "calling " + LUA_QS + " on bad self ({1})", ar.name, extramsg); } if (ar.name == null) ar.name = "?"; return LuaLError(L, "bad argument #%d to " + LUA_QS + " (%s)", narg, ar.name, extramsg); }
private void DebugHookCallbackInternal(LuaState luaState, LuaDebug luaDebug) { try { var temp = DebugHook; if (temp != null) temp(this, new DebugHookEventArgs(luaDebug)); } catch (Exception ex) { OnHookException(new HookExceptionEventArgs(ex)); } }
public static CharPtr LuaGetLocal (LuaState L, LuaDebug ar, int n) { CallInfo ci = L.base_ci[ar.i_ci]; CharPtr name = FindLocal(L, ci, n); LuaLock(L); if (name != null) LuaAPushObject(L, ci.base_[n - 1]); LuaUnlock(L); return name; }
/* }====================================================== */ /* ** {====================================================== ** 'module' function ** ======================================================= */ private static void SetFEnv(LuaState L) { LuaDebug ar = new LuaDebug(); if (LuaGetStack(L, 1, ar) == 0 || LuaGetInfo(L, "f", ar) == 0 || /* get calling function */ LuaIsCFunction(L, -1)) LuaLError(L, LUA_QL("module") + " not called from a Lua function"); LuaPushValue(L, -2); LuaSetFEnv(L, -2); LuaPop(L, 1); }
private static int DBGetLocal(LuaState L) { int arg; LuaState L1 = GetThread(L, out arg); LuaDebug ar = new LuaDebug(); CharPtr name; if (LuaGetStack(L1, LuaLCheckInt(L, arg+1), ar)==0) /* out of range? */ return LuaLArgError(L, arg+1, "level out of range"); name = LuaGetLocal(L1, ar, LuaLCheckInt(L, arg+2)); if (name != null) { LuaXMove(L1, L, 1); LuaPushString(L, name); LuaPushValue(L, -2); return 2; } else { LuaPushNil(L); return 1; } }
/// <summary> /// Sets local (see lua docs) /// </summary> /// <param name = "luaDebug">lua debug structure</param> /// <param name = "n">see lua docs</param> /// <returns>see lua docs</returns> /// <author>Reinhard Ostermeier</author> public string SetLocal(LuaDebug luaDebug, int n) { return LuaCore.LuaSetLocal(luaState, luaDebug, n).ToString(); }