Skip to content

Conversation

@jamesrom
Copy link

@jamesrom jamesrom commented Apr 12, 2020

Using CSharp.lua's method of inserting Lua code, we can leverage that to allow access to global variables from C#.

Using [CSharp.lua's method of inserting Lua code](https://github.com/yanghuan/CSharp.lua/wiki/FAQ_en#7how-do-you-call-or-insert-lua-code-in-your-code), we can leverage that to allow access to global variables from C#.
@Drake53
Copy link
Owner

Drake53 commented Apr 12, 2020

It's easier to write using CSharpLua.Template:

/// @CSharpLua.Template = "rawget(System.global, {0})"
public static extern T GetGlobal<T>(string key);

@Drake53
Copy link
Owner

Drake53 commented Apr 20, 2020

I just tested this method, it works when added directly to the source, but not when added as a package (.dll/.xml). This is due to a bug in my fork of CSharpLua, which is unable to parse the documentation .xml file properly: it cannot find the CSharpLua.Template attribute, because you added documentation xml nodes to it (summary, etc). I'll have to fix this bug before I can merge your PR.

@Drake53
Copy link
Owner

Drake53 commented Apr 21, 2020

Did some more testing, and it turns out I incorrectly assumed it was caused by the documentation. The real cause is the generic type argument (in combination with it being passed to the transpiler as a .dll instead of .cs).

Related: https://github.com/yanghuan/CSharp.lua/wiki/FAQ_en#9how-to-change-some-of-the-generated-behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants