tolua笔记《04》- Lua Function调用

在前面几篇中已经介绍了C#如何调用Lua脚本,本篇中我们进一步通过**03_CallLuaFunction**s示例进一步了解Lua脚本中的Function是如何调用的。

演示效果

tolua笔记《04》- Lua Function调用_第1张图片


示例代码
using UnityEngine;
using System.Collections;
using LuaInterface;
using System;

public class CallLuaFunction : MonoBehaviour 
{
    private string script =
        @"  function luaFunc(num)                        
                return num + 1
            end

            test = {}
            test.luaFunc = luaFunc
        ";

    LuaFunction luaFunc = null;
    LuaState lua = null;
    string tips = null;

    void Start () 
    {
#if UNITY_5 || UNITY_2017 || UNITY_2018
        Application.logMessageReceived += ShowTips;
#else
        Application.RegisterLogCallback(ShowTips);
#endif
        new LuaResLoader();
        lua = new LuaState();
        lua.Start();
        DelegateFactory.Init();        
        lua.DoString(s

你可能感兴趣的:(游戏开发,tolua,unity3d,热更新)