예제 #1
0
파일: ToLua.cs 프로젝트: zhangf911/tolua
        static bool IsMatchUserData(IntPtr L, Type t, int pos)
        {
            object obj   = null;
            int    udata = LuaDLL.tolua_rawnetobj(L, pos);

            if (udata != -1)
            {
                ObjectTranslator translator = LuaState.GetTranslator(L);
                obj = translator.GetObject(udata);

                if (obj != null)
                {
                    Type objType = obj.GetType();

                    if (t == objType || t.IsAssignableFrom(objType))
                    {
                        return(true);
                    }
                }
                else
                {
                    return(!t.IsValueType);
                }
            }

            return(false);
        }
예제 #2
0
파일: ToLua.cs 프로젝트: zhangf911/tolua
        public static object CheckObject(IntPtr L, int stackPos, Type type)
        {
            int udata = LuaDLL.tolua_rawnetobj(L, stackPos);

            if (udata != -1)
            {
                ObjectTranslator translator = LuaState.GetTranslator(L);
                object           obj        = translator.GetObject(udata);

                if (obj != null)
                {
                    Type objType = obj.GetType();

                    if (type == objType || type.IsAssignableFrom(objType))
                    {
                        return(obj);
                    }

                    LuaDLL.luaL_argerror(L, stackPos, string.Format("{0} expected, got {1}", type.FullName, objType.FullName));
                }

                return(null);
            }
            else if (LuaDLL.lua_isnil(L, stackPos) && !TypeChecker.IsValueType(type))
            {
                return(null);
            }

            LuaDLL.luaL_typerror(L, stackPos, type.FullName);
            return(null);
        }
예제 #3
0
        public static ObjectTranslator Get(IntPtr L)
        {
#if !MULTI_STATE
            return(_translator);
#else
            return(LuaState.GetTranslator(L));
#endif
        }
예제 #4
0
파일: ToLua.cs 프로젝트: zhangf911/tolua
        public static int Destroy(IntPtr L)
        {
            int udata = LuaDLL.tolua_rawnetobj(L, 1);
            ObjectTranslator translator = LuaState.GetTranslator(L);

            translator.Destroy(udata);
            return(0);
        }
예제 #5
0
파일: ToLua.cs 프로젝트: zhangf911/tolua
        public static void SetBack(IntPtr L, int stackPos, object o)
        {
            int udata = LuaDLL.tolua_rawnetobj(L, stackPos);
            ObjectTranslator translator = LuaState.GetTranslator(L);

            if (udata != -1)
            {
                translator.SetBack(udata, o);
            }
        }
예제 #6
0
파일: ToLua.cs 프로젝트: zhangf911/tolua
        public static object ToObject(IntPtr L, int stackPos)
        {
            int udata = LuaDLL.tolua_rawnetobj(L, stackPos);

            if (udata != -1)
            {
                ObjectTranslator translator = LuaState.GetTranslator(L);
                return(translator.GetObject(udata));
            }

            return(null);
        }
예제 #7
0
파일: ToLua.cs 프로젝트: zhangf911/tolua
        public static int Collect(IntPtr L)
        {
            int udata = LuaDLL.tolua_rawnetobj(L, 1);

            if (udata != -1)
            {
                ObjectTranslator translator = LuaState.GetTranslator(L);
                translator.RemoveObject(udata);
            }

            return(0);
        }
예제 #8
0
    // Use this for initialization
    void Start()
    {
        LuaState l = new LuaState();
        LuaScriptMgr._translator = l.GetTranslator();

        // First run the script so the function is created
        l.DoString(script);

        // Get the function object
        LuaFunction f = l.GetFunction("luaFunc");

        // Call it, takes a variable number of object parameters and attempts to interpet them appropriately
        object[] r = f.Call("I called a lua function!");

        // Lua functions can have variable returns, so we again store those as a C# object array, and in this case print the first one
        print(r[0]);
    }
예제 #9
0
파일: ToLua.cs 프로젝트: zhangf911/tolua
        public static object CheckObject(IntPtr L, int stackPos)
        {
            int udata = LuaDLL.tolua_rawnetobj(L, stackPos);

            if (udata != -1)
            {
                ObjectTranslator translator = LuaState.GetTranslator(L);
                return(translator.GetObject(udata));
            }
            else if (LuaDLL.lua_isnil(L, stackPos))
            {
                return(null);
            }

            LuaDLL.luaL_typerror(L, stackPos, "object");
            return(null);
        }
예제 #10
0
    // Use this for initialization
    void Start()
    {
        LuaState l = new LuaState();
        LuaScriptMgr._translator = l.GetTranslator();

        // First run the script so the function is created
        l.DoString(script);

        // Get the function object
        LuaFunction f = l.GetFunction("myFunc");

        // Create a paused lua coroutine object from the parent state and a function
        co = new LuaThread(l, f);

        // The coroutine needs to be resumed each frame, since it is yielding each frame, alternatively you could only resume it on conditions in C# instead
        co.Start();
    }
    // Use this for initialization
    void Start()
    {
        LuaState l = new LuaState();
        LuaScriptMgr._translator = l.GetTranslator();

        // Assign to global scope variables as if they're keys in a dictionary (they are really)
        l["Objs2Spawn"] = 5;
        l.DoString(script);

        // Read from the global scope the same way
        print("Read from lua: " + l["var2read"].ToString());

        // Get the lua table as LuaTable object
        LuaTable particles = (LuaTable)l["particles"];

        // Typical foreach over values in table
        foreach( ParticleSystem ps in particles.Values )
        {
            ps.Play();
        }
    }
예제 #12
0
파일: ToLua.cs 프로젝트: zhangf911/tolua
        public static UnityEngine.Object CheckUnityObject(IntPtr L, int stackPos, Type type)
        {
            int    udata = LuaDLL.tolua_rawnetobj(L, stackPos);
            object obj   = null;

            if (udata != -1)
            {
                ObjectTranslator translator = LuaState.GetTranslator(L);
                obj = translator.GetObject(udata);

                if (obj != null)
                {
                    UnityEngine.Object uObj = (UnityEngine.Object)obj;

                    if (uObj == null)
                    {
                        LuaDLL.luaL_argerror(L, stackPos, string.Format("{0} expected, got nil", type.FullName));
                        return(null);
                    }

                    Type objType = uObj.GetType();

                    if (type == objType || objType.IsSubclassOf(type))
                    {
                        return(uObj);
                    }

                    LuaDLL.luaL_argerror(L, stackPos, string.Format("{0} expected, got {1}", type.FullName, objType.FullName));
                }

                return(null);
            }
            else if (LuaDLL.lua_isnil(L, stackPos))
            {
                return(null);
            }

            LuaDLL.luaL_typerror(L, stackPos, type.FullName);
            return(null);
        }
예제 #13
0
 // Use this for initialization
 void Start()
 {
     LuaState l = new LuaState();
     LuaScriptMgr._translator = l.GetTranslator();
     l.DoString(scriptFile.text);
 }