nrother / dynamiclua

Wrapper for NLua, making access to lua more idomatic from .NET. Heavily using the "dynamic" keyword.
63 stars 10 forks source link

import() Method is not available #9

Closed nrother closed 10 years ago

nrother commented 10 years ago

This code should work, but won't:

import("System.Windows.Forms")
form = Form()
form:ShowDialog()

DynamicLua does not call the method LoadCLRPackage() of NLua, therefore acessing or even importing the CLR classes does not work.

This is a workarround/hack to fix it:

var internalLua = typeof(DynamicLua.DynamicLua).GetMethod("get_LuaInstance", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(lua, new object[0]);
Type luaType = internalLua.GetType();
luaType.GetMethod("LoadCLRPackage").Invoke(internalLua, new object[0]);

This is a pretty nasty bug, since this is one of the really cool features of NLua :frowning:

nrother commented 10 years ago

Until the fix is included in the NuGet package: You can always use luanet:

luanet.load_assembly("System.Windows.Forms")
Form = luanet.import_type("System.Windows.Forms.Form")
form = Form()
form.Text = "This is a cool dialog"
form:ShowDialog()
form = nil

Not so cool as the import() way, but it works!