如果是c#代码出错了
[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
static int _g_get_down(RealStatePtr L)
{
try {
ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
translator.PushUnityEngineVector3(L, UnityEngine.Vector3.down);
} catch(System.Exception gen_e) {
return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
}
return 1;
}
会在所有导出的方法里,增加try catch,然后把错再抛到lua里。
如果是lua代码出错了
[MonoPInvokeCallback(typeof(LuaCSFunction))]
internal static int Panic(RealStatePtr L)
{
string reason = String.Format("unprotected error in call to Lua API ({0})", LuaAPI.lua_tostring(L, -1));
throw new LuaException(reason);
}