LuaInterface.LuaMethod.Call C# (CSharp) Method

Call() public method

public Call ( IntPtr L ) : int
L System.IntPtr
return int
        public int Call(IntPtr L)
        {
            object[] args = null;
            object obj = null;
            int offset = 1;

            if (!method.IsStatic)
            {
                offset += 1;
                obj = ToLua.CheckObject(L, 2, kclass);
            }

            ToLua.CheckArgsCount(L, list.Count + offset);

            if (list.Count > 0)
            {
                args = new object[list.Count];
                offset += 1;

                for (int i = 0; i < list.Count; i++)
                {
                    bool isRef = list[i].IsByRef;
                    Type t0 = isRef ? list[i].GetElementType() : list[i];
                    object o = ToLua.CheckVarObject(L, i + offset, t0);
                    args[i] = TypeChecker.ChangeType(o, t0);
                }
            }

            object ret = method.Invoke(obj, args);
            int count = 0;

            if (method.ReturnType != typeof(void))
            {
                ++count;
                ToLua.Push(L, ret);
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].IsByRef)
                {
                    ++count;
                    ToLua.Push(L, args[i]);
                }
            }

            return count;
        }

Usage Example

 static int Call(IntPtr L)
 {
     try
     {
         LuaInterface.LuaMethod obj = (LuaInterface.LuaMethod)ToLua.CheckObject(L, 1, typeof(LuaInterface.LuaMethod));
         return(obj.Call(L));
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }