Example #1
0
    void main()
    {
        if (!Directory.Exists(CSTools.GetPlatformPath()))
        {
            Directory.CreateDirectory(CSTools.GetPlatformPath());
            FileStream   fs   = new FileStream(CSTools.GetPlatformPath() + "/Main.lua", FileMode.Create);
            StreamWriter sw   = new StreamWriter(fs);
            string       text = "function main() print('hello LuaShow!') end";
            sw.Write(text);
            sw.Flush();
            sw.Close();
            fs.Close();
        }
        LuaEnv luaEnv = new LuaEnv();

        CSTools.Instance.LoadText("Main.lua", (luaScript) => {
            LuaTable scriptEnv = luaEnv.NewTable();
            LuaTable meta      = luaEnv.NewTable();
            meta.Set("__index", luaEnv.Global);
            scriptEnv.SetMetaTable(meta);
            meta.Dispose();
            scriptEnv.Set("self", this);
            luaEnv.DoString(luaScript, "Main.lua", scriptEnv);
            Action luaMain = scriptEnv.Get <Action> ("main");
            luaMain();
        });
    }
Example #2
0
 void Awake()
 {
     Instance = this;
 }