public object[] MessageToLua(LuaFunction luaFunction, object[] args) { try { if (args == null) { return luaFunction.Call(); } else { return luaFunction.Call(args); } } catch (Exception ex) { if (ex is KopiLua.Lua.LuaException) { Console.LogError(new LocalizedString(GlobalConsts.ID_ERROR_LUA_EXCEPTION, "LuaException in %s!\n%s", new object[] { name, ex })); } else { Console.LogError(new LocalizedString(GlobalConsts.ID_ERROR_GENERIC_EXCEPTION, "Exception: %s", new object[] { ex })); } return null; } }
/* * Calls the provided function with the provided parameters */ public static object callFunction(LuaFunction function, object[] args, Type[] returnTypes, object[] inArgs, int[] outArgs) { // args is the return array of arguments, inArgs is the actual array // of arguments passed to the function (with in parameters only), outArgs // has the positions of out parameters object returnValue; int iRefArgs; object[] returnValues = function.call(inArgs, returnTypes); if(returnTypes[0] == typeof(void)) { returnValue = null; iRefArgs = 0; } else { returnValue = returnValues[0]; iRefArgs = 1; } for(int i = 0; i < outArgs.Length; i++) { args[outArgs[i]] = returnValues[iRefArgs]; iRefArgs++; } return returnValue; }
public static LuaValue lines(LuaValue[] values) { LuaUserdata data = values[0] as LuaUserdata; //[PixelCrushers]TextReader reader = data.Value as TextReader; LuaFunction func = new LuaFunction((LuaValue[] args) => { //[PixelCrushers]LuaUserdata _data = values[0] as LuaUserdata; TextReader _reader = data.Value as TextReader; string line = _reader.ReadLine(); if (line != null) { return new LuaString(line); } else { return LuaNil.Nil; } } ); return new LuaMultiValue(new LuaValue[] { func, data, LuaNil.Nil }); }
public object Register(LuaFunction o) { Func<IComponentContext, IEnumerable<Parameter>, object> d = (a, p) => this.Call(o, a, p); var rb = RegistrationBuilder.ForDelegate(d); this.builder.RegisterCallback((Action<IComponentRegistry>)(cr => RegistrationBuilder.RegisterSingleComponent<object, SimpleActivatorData, SingleRegistrationStyle>(cr, rb))); return rb; }
static public IEnumerator yieldReturn(object y, LuaFunction f) { if (y is IEnumerator) yield return mb.StartCoroutine((IEnumerator)y); else yield return y; f.call(); }
private object Call(LuaFunction luaFunction, IComponentContext componentContext, IEnumerable<Parameter> parameters) { var args = new List<LuaObject>(); args.Add(LuaObject.FromUserData(componentContext)); args.AddRange(from p in parameters select LuaObject.FromUserData(p)); LuaObject objects = luaFunction.Invoke(args.ToArray()); return objects.AsUserData(); }
/* * Adds a new event handler */ public Delegate Add (LuaFunction function) { //CP: Fix by Ben Bryant for event handling with one parameter //link: http://luaforge.net/forum/message.php?msg_id=9266 Delegate handlerDelegate = CodeGeneration.Instance.GetDelegate (eventInfo.EventHandlerType, function); eventInfo.AddEventHandler (target, handlerDelegate); pendingEvents.Add (handlerDelegate, this); return handlerDelegate; }
/// <summary> /// /// </summary> /// <param name="parent"></param> /// <param name="eachFn"></param> public static void ForeachChild(GameObject parent, LuaFunction eachFn) { Transform pr=parent.transform; int count = pr.childCount; Transform child = null; for (int i = 0; i < count; i++) { child = pr.GetChild(i); eachFn.call(i, child.gameObject); } }
/// <summary> /// Binds an Lua function to a string. /// </summary> /// <param name='func'> /// The Lua function. /// </param> /// <param name='name'> /// The string used to reference it. /// </param> public void BindMessageFunction(LuaFunction func, string name) { //Binding if (functionList.ContainsKey (name)) { functionList [name] = func; } else { functionList.Add (name, func); } }
/// <summary> /// Find or create a proxy for a function /// </summary> public static LuaCFunctionProxy GetProxy(LuaFunction function) { if (function == null) return null; var result = FindProxy(function); if (result == null) { result = new LuaCFunctionProxy() { ManagedFunction = function }; result.UnmanagedFunction = result.InvokeManagementFunction; _Proxies.Add(result); } return result; }
/* * Adds a new event handler */ public Delegate Add(LuaFunction function) { //CP: Fix by Ben Bryant for event handling with one parameter //link: http://luaforge.net/forum/message.php?msg_id=9266 Delegate handlerDelegate = CodeGeneration.Instance.GetDelegate(eventInfo.EventHandlerType, function); eventInfo.AddEventHandler(target, handlerDelegate); pendingEvents.Add(handlerDelegate, this); return handlerDelegate; //MethodInfo mi = eventInfo.EventHandlerType.GetMethod("Invoke"); //ParameterInfo[] pi = mi.GetParameters(); //LuaEventHandler handler=CodeGeneration.Instance.GetEvent(pi[1].ParameterType,function); //Delegate handlerDelegate=Delegate.CreateDelegate(eventInfo.EventHandlerType,handler,"HandleEvent"); //eventInfo.AddEventHandler(target,handlerDelegate); //pendingEvents.Add(handlerDelegate, this); //return handlerDelegate; }
/** * Call a lua method. * * @param ref LuaFunction cResFunc - The result of the function, if the lua function calls ok, if it is not null, will call it instead of look up from table by strFunc. * @param string strFunc - The function name. * @return object - The number of result. */ public object CallMethod(ref LuaFunction cResFunc, string strFunc) { // Check function first. if (null == cResFunc) { // Check params. if (string.IsNullOrEmpty(strFunc)) { return null; } // Check table. if (null == m_cLuaTable) { return null; } // Check function. object cFuncObj = m_cLuaTable[strFunc]; if ((null == cFuncObj) || !(cFuncObj is LuaFunction)) { return null; } // Get function. cResFunc = (LuaFunction)cFuncObj; if (null == cResFunc) { return null; } } // Try to call this method. try { return cResFunc.call(); } catch (Exception e) { YwDebug.LogError(YwLuaSvr.FormatException(e)); cResFunc = null; return null; } }
public static LuaValue ipairs(LuaValue[] values) { LuaTable table = values[0] as LuaTable; LuaFunction func = new LuaFunction( (LuaValue[] args) => { LuaTable tbl = args[0] as LuaTable; int index = (int)(args[1] as LuaNumber).Number; int nextIndex = index + 1; if (nextIndex <= tbl.Length) { return new LuaMultiValue(new LuaValue[] { new LuaNumber(nextIndex), tbl.GetValue(nextIndex) }); } else { return LuaNil.Nil; } } ); return new LuaMultiValue(new LuaValue[] { func, table, new LuaNumber(0) }); }
public static string Execute(LuaFunction compiledTemplate) { object[] result = compiledTemplate.Call(); System.Diagnostics.Debug.Assert(result.Length == 1); return result[0].ToString(); }
public DG_Tweening_Core_DOSetter_string_Event(LuaFunction func) : base(func) { }
public DG_Tweening_Core_DOSetter_UnityEngine_Quaternion_Event(LuaFunction func) : base(func) { }
public System_Action_Event(LuaFunction func) : base(func) { }
public UnityEngine.AudioClip.PCMSetPositionCallback UnityEngine_AudioClip_PCMSetPositionCallback(LuaFunction func, LuaTable self, bool flag) { if (func == null) { UnityEngine.AudioClip.PCMSetPositionCallback fn = delegate(int param0) { }; return(fn); } if (!flag) { UnityEngine_AudioClip_PCMSetPositionCallback_Event target = new UnityEngine_AudioClip_PCMSetPositionCallback_Event(func); UnityEngine.AudioClip.PCMSetPositionCallback d = target.Call; target.method = d.Method; return(d); } else { UnityEngine_AudioClip_PCMSetPositionCallback_Event target = new UnityEngine_AudioClip_PCMSetPositionCallback_Event(func, self); UnityEngine.AudioClip.PCMSetPositionCallback d = target.CallWithSelf; target.method = d.Method; return(d); } }
/// <summary> /// Execute lua function by name /// </summary> /// <param name="fname">Function name as defined in WoWData.xml</param> /// <param name="param_list">List of parameters</param> /// <param name="res_list">List of parameters needs to be returned</param> /// <returns> /// Array with result. Final array enumerated from 0 to (size of returning list - 1). /// For ex if you need parameters 2 and 5 (total 2) to be returned from lua calls than /// in returning array the parameter 2 can be found by index 0 and parameter 5 by index 1 /// </returns> private string[] ExecLua(LuaFunction lf, object[] param_list, int[] res_list, bool get_all) { string[] res = null; // Check number of parameters int pcount = (param_list == null) ? 0 : param_list.Length; if (lf.ParamSize != pcount) ProcessManager.TerminateOnInternalBug( ProcessManager.Bugs.WRONG_LUA_PARAMETER_LIST, "Number of parameters '" + pcount + "' different from " + lf.ParamSize + " that configured for lua function '" + lf.Name + "'. Terminating application."); // format lua code with parameter list string code = lf.Code; if (param_list != null) { try { code = string.Format(code, param_list); } catch (Exception e) { ProcessManager.TerminateOnInternalBug( ProcessManager.Bugs.WRONG_LUA_RESULT_LIST, "Unable format parameters '" + param_list.ToString() + "' with lua function '" + lf.Name + "'. " + e.Message); } } // Check if result expected if (!get_all && (res_list == null)) Lua_DoString(code); else { Lua_DoStringEx(code); values = RemoteObject.GetValues(); // Check returning result if (values == null) ProcessManager.TerminateOnInternalBug( ProcessManager.Bugs.NULL_LUA_RETURN, "Null returning result from lua function '" + lf.Name + "'"); if (get_all) { res = new string[values.Count]; values.CopyTo(res); } else { if (values.Count != res_list.Length) ProcessManager.TerminateOnInternalBug( ProcessManager.Bugs.WRONG_LUA_RETURN_LIST, "Number of returning parameters " + values.Count + " from lua function '" + lf.Name + "' is different from expected " + res_list.Length); res = new string[res_list.Length]; // Initialize returning result for (int i = 0; i < res_list.Length; i++) { if (i == values.Count) break; res[i] = values[i]; } } } return res; }
public static LuaValue pairs(LuaValue[] values) { LuaTable table = values[0] as LuaTable; LuaFunction func = new LuaFunction(next); return new LuaMultiValue(new LuaValue[] { func, table, LuaNil.Nil }); }
public System_Predicate_int_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public System_Predicate_int_Event(LuaFunction func) : base(func) { }
public UnityEngine_Events_UnityAction_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public UnityEngine_Events_UnityAction_Event(LuaFunction func) : base(func) { }
public void RegisterCallback(Trigger trigger, LuaFunction func, ScriptContext context) { Triggerables(trigger).Add(new Triggerable(func, context, self)); }
public Triggerable(LuaFunction function, ScriptContext context, Actor self) { Function = (LuaFunction)function.CopyReference(); Context = context; Self = self.ToLuaValue(Context); }
public void SetCallback(LuaFunction moveCoordinateLuaFunc, LuaFunction touchCoordinateLuaFunc, LuaFunction updateLuaFunc) { this.moveCoordinateLuaFunc = moveCoordinateLuaFunc; this.touchCoordinateLuaFunc = touchCoordinateLuaFunc; this.updateLuaFunc = updateLuaFunc; }
//#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) public static void lua_pushcfunction(IntPtr lua_State, LuaFunction func) { lua_pushcclosure(lua_State, func, 0); }
/// <summary> /// 载入素材 /// </summary> public void LoadAsset(string abname, string assetname, LuaFunction func) { abname = abname.ToLower(); StartCoroutine(OnLoadAsset(abname, assetname, func)); }
public System_Comparison_int_Event(LuaFunction func) : base(func) { }
public static LuaValue loadstring(LuaValue[] values) { LuaString code = values[0] as LuaString; LuaTable enviroment = values[1] as LuaTable; Chunk chunk = LuaInterpreter.Parse(code.Text); LuaFunction func = new LuaFunction( (LuaValue[] args) => { chunk.Enviroment = enviroment; return chunk.Execute(); } ); return func; }
public System_Comparison_int_Event(LuaFunction func, LuaTable self) : base(func, self) { }
protected virtual void StartMain() { luaState.DoFile("Main.lua"); levelLoaded = luaState.GetFunction("OnLevelWasLoaded"); CallMain(); }
public System_Func_int_int_Event(LuaFunction func) : base(func) { }
/// <summary> /// ������壬������Դ������ /// </summary> /// <param name="type"></param> public void CreatePanel(string name, LuaFunction func = null) { StartCoroutine(OnCreatePanel(name, func)); }
public System_Func_int_int_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public System_Action_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public UnityEngine_Camera_CameraCallback_Event(LuaFunction func) : base(func) { }
public DG_Tweening_Core_DOSetter_UnityEngine_Vector4_Event(LuaFunction func) : base(func) { }
public UnityEngine_Camera_CameraCallback_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public static string Execute(LuaFunction compiledTemplate, LuaTable parameters) { compiledTemplate.SetEnv(parameters); object[] result = compiledTemplate.Call(); System.Diagnostics.Debug.Assert(result.Length == 1); return result[0].ToString(); }
/// <summary> /// ����lua ����ļ� /// </summary> public void LoadBundle(LuaFunction onLoadedFn) { //Debug.Log(" refresh LoadBundle "); StopCoroutine(loadLuaBundle(false, onLoadedFn)); StartCoroutine(loadLuaBundle(false, onLoadedFn)); }
public static extern LuaFunction lua_atpanic(IntPtr lua_State, LuaFunction panicf);
/// <summary> /// ����lua bundle /// </summary> /// <returns></returns> private IEnumerator loadLuaBundle(bool domain,LuaFunction onLoadedFn) { string keyName = ""; string luaP = CUtils.GetAssetFullPath("font.u3d"); //Debug.Log("load lua bundle" + luaP); WWW luaLoader = new WWW(luaP); yield return luaLoader; if (luaLoader.error == null) { byte[] byts=CryptographHelper.Decrypt(luaLoader.bytes,DESHelper.instance.Key,DESHelper.instance.IV); AssetBundle item = AssetBundle.CreateFromMemoryImmediate(byts); // item = luaLoader.assetBundle; #if UNITY_5 TextAsset[] all = item.LoadAllAssets<TextAsset>(); foreach (var ass in all) { keyName = Regex.Replace(ass.name,@"\.",""); //Debug.Log("cache : " + keyName); luacache[keyName] = ass; } #else UnityEngine.Object[] all = item.LoadAll(typeof(TextAsset)); foreach (var ass in all) { keyName = Regex.Replace(ass.name,@"\.",""); Debug.Log(keyName + " complete"); luacache[keyName] = ass as TextAsset; } #endif //Debug.Log("loaded lua bundle complete" + luaP); // luaLoader.assetBundle.Unload(false); item.Unload(false); luaLoader.Dispose(); } DoUnity3dLua(); if (domain) DoMain(); if (onLoadedFn != null) onLoadedFn.call(); }
//#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) public static void lua_register(IntPtr lua_State, string n, LuaFunction func) { lua_pushcfunction(lua_State, func); lua_setglobal(lua_State, n); }
public static void Delay(LuaFunction luafun, float time, object args = null) { _instance.StartCoroutine(DelayDo(luafun, args, time)); }
IEnumerator OnLoadAsset(string abname, string assetName, LuaFunction func) { yield return new WaitForEndOfFrame(); GameObject go = LoadAsset(abname, assetName); if (func != null) func.Call(go); }
public DG_Tweening_Core_DOGetter_UnityEngine_Color_Event(LuaFunction func) : base(func) { }
public UnityEngine_AudioClip_PCMReaderCallback_Event(LuaFunction func) : base(func) { }
public UnityEngine_AudioClip_PCMSetPositionCallback_Event(LuaFunction func) : base(func) { }
public bool Start() { lock (FLock) { FLua = CreateLuaVM(); FLua.DoFile(FBotDesc.Script); FLua.NewTable("BotEvent"); FLuaEvent = FLua.GetTable("BotEvent"); FLuaEventHandler = FLua.GetFunction("OnEvent"); BotEvent_Start startEvent = new BotEvent_Start(FBotId); EmmitBotEvent(startEvent); return startEvent.ret_val; } }
public UnityEngine_AudioClip_PCMSetPositionCallback_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public UnityEngine_Application_LogCallback_Event(LuaFunction func) : base(func) { }
public DG_Tweening_Core_DOSetter_UnityEngine_RectOffset_Event(LuaFunction func) : base(func) { }
private static IEnumerator DelayDo(LuaFunction luafun, object arg, float time) { yield return new WaitForSeconds(time); luafun.call(arg); }
public UnityEngine_Application_LogCallback_Event(LuaFunction func, LuaTable self) : base(func, self) { }
void OnDestroy() { if (onDestroyFn != null) onDestroyFn.call(); updateFn = null; if (lua != null) lua.luaState.Close(); lua = null; _instance = null; if(net!=null)net.Dispose(); net = null; if(ChatNet!=null)ChatNet.Dispose(); ChatNet = null; luacache.Clear(); }
public UnityEngine_Application_AdvertisingIdentifierCallback_Event(LuaFunction func, LuaTable self) : base(func, self) { }
/// <summary> /// Execute lua function by name /// </summary> /// <param name="fname">Function name as defined in WoWData.xml</param> /// <param name="param_list">List of parameters</param> /// <param name="res_list">List of parameters needs to be returned</param> /// <returns> /// Array with result. Final array enumerated from 0 to (size of returning list - 1). /// For ex if you need parameters 2 and 5 (total 2) to be returned from lua calls than /// in returning array the parameter 2 can be found by index 0 and parameter 5 by index 1 /// </returns> private string[] ExecLua(LuaFunction lf, object[] param_list, int[] res_list, bool get_all) { string[] res = null; // format lua code with parameter list string code = lf.Code; if (param_list != null) { try { code = string.Format(code, param_list); } catch (Exception e) { ShowError("Internal bug. Unable format parameters '" + param_list.ToString() + "' with lua function '" + lf.Name + "'. " + e.Message); Environment.Exit(6); } } // Check if result expected if (!get_all && (res_list == null)) Lua_DoString(code); else { Lua_DoStringEx(code); values = RemoteObject.GetValues(); if (get_all) { res = new string[values.Count]; values.CopyTo(res); } else { res = new string[res_list.Length]; // Initialize returning result int i = 0; foreach (int id in res_list) { if ((values != null) && (id < values.Count) && (values[id] != null)) res[i] = values[id]; i++; } } } return res; }
public UnityEngine.Application.AdvertisingIdentifierCallback UnityEngine_Application_AdvertisingIdentifierCallback(LuaFunction func, LuaTable self, bool flag) { if (func == null) { UnityEngine.Application.AdvertisingIdentifierCallback fn = delegate(string param0, bool param1, string param2) { }; return(fn); } if (!flag) { UnityEngine_Application_AdvertisingIdentifierCallback_Event target = new UnityEngine_Application_AdvertisingIdentifierCallback_Event(func); UnityEngine.Application.AdvertisingIdentifierCallback d = target.Call; target.method = d.Method; return(d); } else { UnityEngine_Application_AdvertisingIdentifierCallback_Event target = new UnityEngine_Application_AdvertisingIdentifierCallback_Event(func, self); UnityEngine.Application.AdvertisingIdentifierCallback d = target.CallWithSelf; target.method = d.Method; return(d); } }