views:

66

answers:

1

I'm trying to just get a VB.net app to be able to execute a lua script in a external file, and be able to add some functions to lua too, To do this I have this code:

Imports LuaInterface
Public Class Form1
Public luascripting As New Lua()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
luascripting.RegisterFunction("DisplayText", Me, Me.GetType().GetMethod("DisplayText"))
luascripting.DoFile("script.lua")
End Sub
End Class

But it errors on the register function, saying "Object reference not set to an instance of an object." Do you know of a example VB.net project that uses lua? Or know how to fix this?

+2  A: 

You are registering a function but you forgot to write it. Paste this into your form code:

Public Sub DisplayText()
    MsgBox("Works")
End Sub
Hans Passant
AHA! The problem was that it wasn't a public sub! (I did have it though, I just didn't put my entire code.)
Bubby4j
No, the real problem beyond the poor code snippet is that you forgot to specify the BindingFlags for GetMethod(). You need BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.Public. For the record.
Hans Passant