neolithos / neolua

A Lua implementation for the Dynamic Language Runtime (DLR).
https://neolua.codeplex.com/
Apache License 2.0
471 stars 76 forks source link

Register a static class in LuaTable? #83

Closed SystemKeeper closed 5 years ago

SystemKeeper commented 6 years ago

NeoLua Version: 1.3.2

Hello,

please consider the follwing static class:

public static class MyStaticClass
{
  public static string MyStaticFunc()
  {
    return "ABC";
  }
}

Currently I'm doing something like this:

_env = _lua.CreateEnvironment();
dynamic _denv = _env;

_denv.myapp = new LuaTable();
_env.DoChunk("myapp.statictest = clr.NameSpace.MyStaticClass;", "statictest");

which is working fine, but I'm wondering if there's a way to do this in the host application? Something like this: _denv.myapp.statictest = typeof(MyStaticClass); ?

Thanks in advance!

neolithos commented 6 years ago

Just use _denv.myapp.statictest = LuaType.GetType(typeof(MyStaticClass));. This is basicly the same like clr.NameSpace.MyStaticClass in the lua code.

SystemKeeper commented 6 years ago

Thank you very much, this is working perfectly. I submitted a PR to add this as an example to the documentation.