zoukankan      html  css  js  c++  java
  • Ulua_toLua_基本案例(八)_LuaAccessingArray

    Ulua_toLua_基本案例(八)_LuaAccessingArray

    using UnityEngine;
    using LuaInterface;
    
    public class AccessingArray : MonoBehaviour 
    {
        private string script =
            @"
                function TestArray(strs)
                    local len = strs.Length
                    
                    for i = 0, len - 1 do
                        print(strs[i])
                    end
                    return 1, '123', true
                end            
            ";
    
        void Start()
        {
            LuaState lua = new LuaState();
            lua.Start();
            lua.DoString(script);
    
            string[] strs = { "aaa", "bbb", "ccc" };
            LuaFunction func = lua.GetFunction("TestArray");
    
            func.BeginPCall();
            func.Push(strs);
            func.PCall();
            double arg1 = func.CheckNumber();
            string arg2 = func.CheckString();
            bool arg3 = func.CheckBoolean();
            Debugger.Log("return is {0} {1} {2}", arg1, arg2, arg3);
            func.EndPCall();
    
            //转换一下类型,避免可变參数拆成多个參数传递
            object[] objs = func.Call((object)strs);
    
            if (objs != null)
            {
                Debugger.Log("return is {0} {1} {2}", objs[0], objs[1], objs[2]);
            }
    
            lua.CheckTop();
            func.Dispose();
            lua.Dispose();
        }
    }
    


  • 相关阅读:
    mem 预留内存
    关于内核反汇编,同时显示源文件
    读些笔记
    platform设备驱动
    glut 右键子菜单
    获取HINSTANCE
    window窗口样式style
    opengl 直线拾取
    glut弹出式菜单
    读取大恒采集卡c++代码
  • 原文地址:https://www.cnblogs.com/mthoutai/p/7357043.html
Copyright © 2011-2022 走看看