Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a typesafe way to get global variables #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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