开发者

Using LuaInterface with VB.net

I'm trying to wire up Lua to my VB.net game I am making. Now, I've read enough to know that I can wire each function up by开发者_JAVA技巧 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.

RegisterFunction just seems sloppy and not enough.

Thanks for any help!


My first piece of advise is to not use 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; XNA and OpenTK should work cross platform under mono for the graphics engine.

i found this out myself when experementing with LUA for my own vb.net based game, and eventually decided on iron python.

But assuming you want to stick with 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:

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:

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

You can add a new case for each class you want lua to be able to create an instance of; 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.

Although I'll be honest IronPython really is more suited to this kind of thing, and is still being actively developed, unlike 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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜