从NLua获取功能列表 [英] Get list of Functions from NLua

查看:54
本文介绍了从NLua获取功能列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将NLua用于我的应用程序的脚本界面如果我的应用程序使用多个文件,例如one.lua和two.lua

I am using NLua for script interface with my application if my application takes multiple files such as one.lua and two.lua

我想将所有文件中的所有功能都放入luafunctions列表中

i want to get all the functions in all files in to a list of luafunctions

List<LuaFunctions> Functions;

NLua似乎没有这种功能,但是有没有解决的办法,有一个GetFunction(string)方法将返回您命名的函数,我可以在GetFunction方法上执行蛮力方法,但这会使我的应用程序花费数小时才能启动.

NLua doesnt seem to have such a feature, but is there a way around it, there is a GetFunction(string) methodthat will return the function that you named, i can ofc do a brute force method on the GetFunction method but that will make my application take hours to start up with.

有什么方法可以解决此问题,并将所有文件中的所有功能都保存到luafunctions列表中?

Any ways to work around this and get all functions in all files to a list of luafunctions?

推荐答案

由于无法一目了然地列出函数,所以几个小时后我发现了另一种解决方法.

As functions cannot be listed out of the blue, i found another way around it a couple of hours later.

i在表上列出了所有功能.所以我的lua代码:

i listed all functions on a table. so my lua code:

function Start()
   // something
end

function Update()
   // something else
end

变成这样:

var main = {}

function main.Start()
   // something
end

function main.Update()
   // something else
end

那样,我可以使用

lua.GetTable({tablename});

我为之编写的要求必须与该文件命名相同,这样它将变成:

which i have written a requirement for has to be named the same as the file so it would become:

var funcList = lua.GetTable(Path.GetFileNameWithoutExtension(c:\main.lua));

将采用并列出所有功能,然后我们可以使用:

that would take and list all functions and then we can use:

lua.GetFunction(funcList[0]).Call();

为例.花了我一段时间找到这种解决方法,希望它对某人有益.

as an example. Took me a while to find this work-around and i hope it will benefit someone.

这篇关于从NLua获取功能列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆