Example #1
0
 public void AddGlobalFunction(string key, LuaFunction function)
 {
     if (!mGlobalFunction.ContainsKey(key))
         mGlobalFunction.Add(key, function);
     else
         mGlobalFunction[key] = function;
 }
Example #2
0
	public static Delegate UnityEngine_Events_UnityAction(LuaFunction func)
	{
		UnityEngine.Events.UnityAction d = () =>
		{
			func.Call();
		};
		return d;
	}
Example #3
0
	public static Delegate Action(LuaFunction func)
	{
		Action d = () =>
		{
			func.Call();
		};
		return d;
	}
Example #4
0
	public static Delegate CreateDelegate(Type t, LuaFunction func)
	{
		DelegateValue create = null;

		if (!dict.TryGetValue(t, out create))
		{
			Debugger.LogError("Delegate {0} not register", t.FullName);
			return null;
		}
		return create(func);
	}
Example #5
0
	public static Delegate Action_GameObject(LuaFunction func)
	{
		Action<GameObject> d = (param0) =>
		{
			int top = func.BeginPCall();
			IntPtr L = func.GetLuaState();
			LuaScriptMgr.Push(L, param0);
			func.PCall(top, 1);
			func.EndPCall(top);
		};
		return d;
	}
Example #6
0
	public static Delegate System_Reflection_TypeFilter(LuaFunction func)
	{
		System.Reflection.TypeFilter d = (param0, param1) =>
		{
			int top = func.BeginPCall();
			IntPtr L = func.GetLuaState();
			LuaScriptMgr.Push(L, param0);
			LuaScriptMgr.PushVarObject(L, param1);
			func.PCall(top, 2);
			object[] objs = func.PopValues(top);
			func.EndPCall(top);
			return (bool)objs[0];
		};
		return d;
	}
Example #7
0
	// Use this for initialization
	void Start () {
        LuaScriptMgr mgr = new LuaScriptMgr();
        
        mgr.DoString(script);

        // Get the function object
        func = mgr.GetLuaFunction("luaFunc");

        //有gc alloc
        object[] r = func.Call(123456);        
        print(r[0]);

        // no gc alloc
        int num = CallFunc();
        print(num);
	}
Example #8
0
	public static Delegate Application_LogCallback(LuaFunction func)
	{
		Application.LogCallback d = (param0, param1, param2) =>
		{
			int top = func.BeginPCall();
			IntPtr L = func.GetLuaState();
			LuaScriptMgr.Push(L, param0);
			LuaScriptMgr.Push(L, param1);
			LuaScriptMgr.Push(L, param2);
			func.PCall(top, 3);
			func.EndPCall(top);
		};
		return d;
	}
Example #9
0
	public static Delegate AudioClip_PCMSetPositionCallback(LuaFunction func)
	{
		AudioClip.PCMSetPositionCallback d = (param0) =>
		{
			int top = func.BeginPCall();
			IntPtr L = func.GetLuaState();
			LuaScriptMgr.Push(L, param0);
			func.PCall(top, 1);
			func.EndPCall(top);
		};
		return d;
	}
 /*
  * Gets an event handler for the event type that delegates to the eventHandler Lua function.
  * Caches the generated type.
  */
 public LuaEventHandler GetEvent(Type eventHandlerType, LuaFunction eventHandler)
 {
     Type eventConsumerType;
     if (eventHandlerCollection.ContainsKey(eventHandlerType))
     {
         eventConsumerType=eventHandlerCollection[eventHandlerType];
     }
     else
     {
         eventConsumerType=GenerateEvent(eventHandlerType);
         eventHandlerCollection[eventHandlerType] = eventConsumerType;
     }
     LuaEventHandler luaEventHandler=(LuaEventHandler)Activator.CreateInstance(eventConsumerType);
     luaEventHandler.handler=eventHandler;
     return luaEventHandler;
 }
Example #11
0
 /*
  * 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;
 }
Example #12
0
 public LuaDelegate()
 {
     function = null;
     returnTypes = null;
 }
Example #13
0
        /*
         * Adds a new event handler
         */
        public Delegate Add(LuaFunction function)
        {
#if __NOGEN__
			//translator.throwError(luaState,"Delegates not implemnented");
			return null;
#else
            //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;
#endif


            //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;
        }
Example #14
0
 public LuaDelegate(LuaFunction func, LuaTable self)
 {
     this.func = func;
     this.self = self;
 }
Example #15
0
 public LuaDelegate(LuaFunction func)
 {
     this.func = func;
 }
 /*
  * Gets a delegate with delegateType that calls the luaFunc Lua function
  * Caches the generated type.
  */
 public Delegate GetDelegate(Type delegateType, LuaFunction luaFunc)
 {
     List<Type> returnTypes=new List<Type>();
     Type luaDelegateType;
     if (delegateCollection.ContainsKey(delegateType))
     {
         luaDelegateType=delegateCollection[delegateType];
     }
     else
     {
         luaDelegateType=GenerateDelegate(delegateType);
         delegateCollection[delegateType] = luaDelegateType;
     }
     MethodInfo methodInfo=delegateType.GetMethod("Invoke");
     returnTypes.Add(methodInfo.ReturnType);
     foreach(ParameterInfo paramInfo in methodInfo.GetParameters())
         if(paramInfo.ParameterType.IsByRef)
             returnTypes.Add(paramInfo.ParameterType);
     LuaDelegate luaDelegate=(LuaDelegate)Activator.CreateInstance(luaDelegateType);
     luaDelegate.function=luaFunc;
     luaDelegate.returnTypes=returnTypes.ToArray();
     return Delegate.CreateDelegate(delegateType,luaDelegate,"CallFunction");
 }
Example #17
0
	public static Delegate TestLuaDelegate_VoidDelegate(LuaFunction func)
	{
		TestLuaDelegate.VoidDelegate d = (param0) =>
		{
			int top = func.BeginPCall();
			IntPtr L = func.GetLuaState();
			LuaScriptMgr.Push(L, param0);
			func.PCall(top, 1);
			func.EndPCall(top);
		};
		return d;
	}
Example #18
0
 public static void OnSharpCall(LuaTable self, LuaFunction func) {
     func.Call(self);
 }