简体   繁体   English

在VB.net中使用LuaInterface

[英]Using LuaInterface with VB.net

I'm trying to wire up Lua to my VB.net game I am making. 我正在尝试将Lua连接到我正在制作的VB.net游戏中。 Now, I've read enough to know that I can wire each function up by itself like seen here: 现在,我已经阅读了足够的知识,我可以自己连接每个功能,如下所示:

pLuaVM.RegisterFunction("quit", pPrg.GetType(), pPrgType.GetMethod("quit"))

Now, how would I make it possible for my Lua scripters to instance classes, change properties of those classes, etc. 现在,我将如何使我的Lua脚本编写器实例化类,更改这些类的属性等。

RegisterFunction just seems sloppy and not enough. RegisterFunction看起来很邋and而且还不够。

Thanks for any help! 谢谢你的帮助!

My first piece of advise is to not use LUAInterface; 我的第一条建议是不要使用LUAInterface; as it isn't cross platform, and to instead use IronPython, which is just as easy to pick up as LUA, and will run on Windows and OSX, depending on how you are writing your game; 因为它不是跨平台的,而是使用IronPython,它就像LUA一样容易上手,并且可以在Windows和OSX上运行,具体取决于你编写游戏的方式; XNA and OpenTK should work cross platform under mono for the graphics engine. XNA和OpenTK应该在单声道下跨平台工作,用于图形引擎。

i found this out myself when experementing with LUA for my own vb.net based game, and eventually decided on iron python. 我在使用LUA为我自己的基于vb.net的游戏进行实验时发现了这一点,并最终决定使用铁蟒。

But assuming you want to stick with LUA; 但假设你想坚持使用LUA; here is something you can try. 这是你可以尝试的东西。

Based on the fact that you know: Any vb.net code written cannot be changed after run time, you can do something like this: 基于你知道的事实:编写的任何vb.net代码在运行时都无法更改,你可以这样做:

Public Shared Lua as New LuaInterface

Sub Game()
Dim LuaCaller as New LuaAccess
Lua("LuaAccess") = LuaCaller
End Sub

Public Class LuaAccess 
    Public Sub Grant(NewClass as String, Variable as String)
        Select Case NewClass
               Case "LuaAccess"
                    Lua(Variable) = New LuaAccess
    End Sub
End Class

Then from Lua: 然后从Lua:

LuaAccess:Grant("LuaAccess", "MyNewLuaAccess")

You can add a new case for each class you want lua to be able to create an instance of; 您可以为希望lua能够创建实例的每个类添加一个新案例; and use that to create new instances of classes. 并使用它来创建类的新实例。 if you want it to be able to modify an active class used by the main program, just make the subs, or variables, or both in the class shared 如果您希望它能够修改主程序使用的活动类,只需在类共享中创建子类或变量或两者

Public Shared MyVar as Integer

That way there is only one copy of the variable, which any part of the application (even Lua) can modify. 这样,变量只有一个副本,应用程序的任何部分(甚至是Lua)都可以修改。

Although I'll be honest IronPython really is more suited to this kind of thing, and is still being actively developed, unlike LuaInterface. 虽然我会说实话IronPython确实更适合这种事情,并且仍然在积极开发,与LuaInterface不同。

remember one thing; 记住一件事; when it comes to scripting, you really don't want to give the scripting engine too much control; 当谈到脚本时,你真的不想给脚本引擎太多控制权; when it comes to games specifically you're giving them access to everything your engine can do; 当谈到游戏时,你可以让他们访问你的引擎可以做的一切; and that can be used to cheat if you are not careful. 如果你不小心,这可以用来作弊。

good luck, and i hope i helped. 祝你好运,我希望我帮助过。

Based on LuaInterface runtime v2.0.50727 (the one that uses Lua51.dll) 基于LuaInterface运行时v2.0.50727(使用Lua51.dll的那个)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM