Esempio n. 1
0
    private void Start()
    {
        Debug.Log("Start called");
        commandVM = new LuaVM(LuaVM.VMSettings.None);
        commandVM.AttachCustomAPI(typeof(CommandApi));

        Logger.OnLog += Logger_OnLog;
        Application.logMessageReceived += Application_logMessageReceived;
        Debug.Log("Attach logged");

        //Set commands as default (not cmd.simg but only simg)
        commandVM.ExecuteString("simg = cmd.simg");
        commandVM.ExecuteString("spawn = cmd.spawn");
    }
    // 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
        }
    }
Esempio n. 3
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);
        }
Esempio n. 4
0
    public static void ExecCmd(int fc, string cmd)
    {
        commandVM.SetGlobal("__me", fc);

        commandVM.ExecuteString(cmd);
    }
 // Start is called before the first frame update
 void Start()
 {
     virtualM = new LuaVM();
     virtualM.ExecuteString(luaCode);
 }