protected internal override object GetFieldImp(object key) { if (_L != IntPtr.Zero) { if (_L.istable(StackPos)) { using (LuaStateRecover lr = new LuaStateRecover(_L)) { _L.pushvalue(StackPos); _L.PushLua(key); _L.gettable(-2); return(_L.GetLua(-1)); } } else { DynamicHelper.LogInfo("luatable on stack: not a table."); } } else { DynamicHelper.LogInfo("luatable on stack: null state."); } return(null); }
protected internal override bool SetFieldImp(object key, object val) { if (_L != IntPtr.Zero) { if (_L.istable(StackPos)) { using (LuaStateRecover lr = new LuaStateRecover(_L)) { _L.pushvalue(StackPos); _L.PushLua(key); _L.PushLua(val); _L.settable(-3); return(true); } } else { DynamicHelper.LogInfo("luatable on stack: not a table."); } } else { DynamicHelper.LogInfo("luatable on stack: null state."); } return(false); }
protected internal override object ConvertBinding(Type type) { if (type == typeof(bool)) { if (L != IntPtr.Zero && StackPos != 0) { bool rv = !L.isnoneornil(StackPos) && !(L.isboolean(StackPos) && !L.toboolean(StackPos)); return(rv); } return(false); } DynamicHelper.LogInfo("__convert(" + type.ToString() + ") meta-method Not Implemented."); return(null); }
protected internal override object GetFieldImp(object key) { if (_L != IntPtr.Zero && Refid != 0) { using (LuaStateRecover lr = new LuaStateRecover(_L)) { _L.getref(Refid); _L.PushLua(key); _L.rawget(-2); return(_L.GetLua(-1)); } } DynamicHelper.LogInfo("luatable raw: null ref"); return(null); }
protected internal override bool SetFieldImp(object key, object val) { if (_L != IntPtr.Zero && Refid != 0) { using (LuaStateRecover lr = new LuaStateRecover(_L)) { _L.getref(Refid); _L.PushLua(key); _L.PushLua(val); _L.rawset(-3); return(true); } } DynamicHelper.LogInfo("luatable raw: null ref"); return(false); }
protected internal override object ConvertBinding(Type type) { if (type.IsSubclassOf(typeof(Delegate))) { return(Capstones.LuaLib.CapsLuaDelegateGenerator.CreateDelegate(type, this)); } if (type == typeof(bool)) { if (L != IntPtr.Zero && Refid != 0) { L.getref(Refid); bool rv = !L.isnoneornil(-1) && !(L.isboolean(-1) && !L.toboolean(-1)); L.pop(1); return(rv); } return(false); } DynamicHelper.LogInfo("__convert(" + type.ToString() + ") meta-method Not Implemented."); return(null); }
public override object[] Call(params object[] args) { if (L != IntPtr.Zero) { if (Refid != 0) { L.getref(Refid); return(L.PushArgsAndCall(args)); } else { DynamicHelper.LogInfo("luafunc : null ref"); } } else { DynamicHelper.LogInfo("luafunc : null state."); } return(null); }
public override object[] Call(params object[] args) { if (L != IntPtr.Zero) { if (L.isfunction(StackPos)) { L.pushvalue(StackPos); return(L.PushArgsAndCall(args)); } else { DynamicHelper.LogInfo("luafunc : the index is not a func."); } } else { DynamicHelper.LogInfo("luafunc : null state."); } return(null); }
public static BaseLua BindBehav(IntPtr l, CapsUnityLuaBehav behav, int index) { ExpandExFields(l, behav, index); using (var lr = new LuaStateRecover(l)) { if (string.IsNullOrEmpty(behav.InitLuaPath)) { l.pushvalue(index); var refid = l.refer(); return(new BaseLua(l, refid)); } int oldtop = lr.Top; bool luaFileDone = false; l.pushcfunction(LuaHub.LuaFuncOnError); l.GetGlobal("require"); l.PushString(behav.InitLuaPath); if (l.pcall(1, 1, -3) == 0) { if (l.gettop() > oldtop + 1 && l.istable(oldtop + 2)) { luaFileDone = true; } else { DynamicHelper.LogError("Failed to init script by require " + behav.InitLuaPath + ". (Not a table.) Now Init it by file."); } } else { DynamicHelper.LogError(l.GetLua(-1)); DynamicHelper.LogInfo("Failed to init script by require " + behav.InitLuaPath + ". Now Init it by file."); } if (!luaFileDone) { DynamicHelper.LogInfo("Init it by file. - Disabled"); //string path = behav.InitLuaPath; //if (path.EndsWith(".lua")) //{ // path = path.Substring(0, path.Length - 4); //} //path = path.Replace('.', '/'); //path = path.Replace('\\', '/'); //if (!path.StartsWith("spt/")) //{ // path = "spt/" + path; //} //path += ".lua"; //path = ResManager.UpdatePath + "/" + path; //l.settop(oldtop); //if (l.dofile(path) == 0) //{ // if (l.gettop() > oldtop && l.istable(oldtop + 1)) // { // luaFileDone = true; // } // else // { // DynamicHelper.LogInfo("Failed to load script " + path + ". (Not a table.)"); // } //} //else //{ // DynamicHelper.LogInfo(l.GetLua(-1).UnwrapDynamic()); // DynamicHelper.LogInfo("Failed to load script " + path); //} } if (luaFileDone) { l.GetField(oldtop + 2, "___bind_ex_to_self"); if (!l.isnoneornil(-1)) { bool bindex; l.GetLua(-1, out bindex); if (bindex) { ExpandExFieldsToSelf(l, behav, oldtop); } } l.pop(1); l.GetField(oldtop + 2, "attach"); if (l.isfunction(-1)) { l.pushvalue(oldtop); if (l.pcall(1, 0, oldtop + 1) == 0) { } else { DynamicHelper.LogError(l.GetLua(-1)); } l.pushvalue(oldtop); var refid = l.refer(); return(new BaseLua(l, refid)); } } } { l.pushvalue(index); var refid = l.refer(); return(new BaseLua(l, refid)); } }