zoukankan      html  css  js  c++  java
  • Ulua_toLua_基本案例(六)_LuaCoroutine2

    Ulua_toLua_基本案例(六)_LuaCoroutine2


    using UnityEngine;
    using System.Collections;
    using LuaInterface;
    
    public class TestCoroutine2 : MonoBehaviour 
    {
        LuaState luaState = null;    
    
        string script =
        @"
            function CoExample()            
                WaitForSeconds(2)
                print('WaitForSeconds end time: '.. UnityEngine.Time.time)
                WaitForFixedUpdate()
                print('WaitForFixedUpdate end frameCount: '..UnityEngine.Time.frameCount)
                WaitForEndOfFrame()
                print('WaitForEndOfFrame end frameCount: '..UnityEngine.Time.frameCount)
                Yield(null)
                print('yield null end frameCount: '..UnityEngine.Time.frameCount)
                Yield(0)
                print('yield(0) end frameCime: '..UnityEngine.Time.frameCount)
                local www = UnityEngine.WWW('http://www.baidu.com')
                Yield(www)
                print('yield(www) end time: '.. UnityEngine.Time.time)
                local s = tolua.tolstring(www.bytes)
                print(s:sub(1, 128))
                print('coroutine over')
            end
    
            function TestCo()
                print('TestCo')
                local co = coroutine.create(CoExample)
                            
                local flag, msg = coroutine.resume(co)
                
                if not flag then
                    error(msg)
                end
            end
        ";
    
    	void Awake () 
        {
            luaState = new LuaState();
            luaState.Start();
            LuaBinder.Bind(luaState);
            LuaCoroutine.Register(luaState, this);
    
            luaState.DoString(script);
            LuaFunction func = luaState.GetFunction("TestCo");
            func.Call();
            func.Dispose();
    	}
    
        void OnDestroy()
        {
            luaState.Dispose();
            luaState = null;
        }
    }
    


  • 相关阅读:
    83. Remove Duplicates from Sorted List
    141. Linked List Cycle
    hdu1028 划分数
    XDU1019 阶乘因子的个数
    poj2773 容斥原理
    poj1091 容斥原理的应用
    poj1173 多重集组合数
    HDU 1465 错排问题
    poj 1496
    复习之求一个数的约束之积模一个质数
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/7364880.html
Copyright © 2011-2022 走看看