// Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            code = LoadFile();
            virtualM.ExecuteString(code);

            // Get table to iterate
            Table fruitTable = virtualM.GetGlobalTable("fruits");
            foreach (DynValue fruit in fruitTable.Values)
            {
                Debug.Log(fruit.String); // Prints "apple" then "banana"
            }

            // Or get a lua function and call it
            DynValue fruitFunction = virtualM.GetGlobal("GetRandomFruit");
            Debug.Log(virtualM.Call(fruitFunction).String); // Prints return of GetRandomFruit
        }
    }
Пример #2
0
        void Awake()
        {
            Script.DefaultOptions.ScriptLoader = new UnityAssetsScriptLoader();


            Vm = new LuaVM(CoreModules.Preset_Complete, new string[]
            {
                "Assets/Resources/Scripts/LuaScripts/?",
                "Assets/Resources/Scripts/LuaScripts/?.txt",
                "Resources/Scripts/LuaScripts/?",
                "Resources/Scripts/LuaScripts/?.txt",
                "Scripts/LuaScripts/?",
                "Scripts/LuaScripts/?.txt",

                "Assets/Resources/Scripts/LuaScripts/?/?",
                "Assets/Resources/Scripts/LuaScripts/?/?.txt",
                "Resources/Scripts/LuaScripts/?/?",
                "Resources/Scripts/LuaScripts/?/?.txt",
                "Scripts/LuaScripts/?/?",
                "Scripts/LuaScripts/?/?.txt",

                "Assets/Resources/Scripts/LuaScripts/?/?/?",
                "Assets/Resources/Scripts/LuaScripts/?/?/?.txt",
                "Resources/Scripts/LuaScripts/?/?/?",
                "Resources/Scripts/LuaScripts/?/?/?.txt",
                "Scripts/LuaScripts/?/?/?",
                "Scripts/LuaScripts/?/?/?.txt",
            });
            ScriptObj = Vm.GetScriptObject();

            LuaLibrariesIniter.InitLibraries(Vm);

            //UnityOs.IsDebugCheck = true;

            var fileText  = UnityOs.GetTextFromFile("main");
            var EvoEngine = Vm.ExecuteString(fileText);
            var main      = EvoEngine.Table.Get("Main");

            InitForLua();

            Vm.Call(main);
        }