Skip to content

Invoking C# code from within Lua? #2

Pinned Answered by Quahu
QuantumToasted asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, any delegate can be marshaled as a Lua function.

Here's an example that sets a global function which, when called, invokes Console.WriteLine(string):

lua.SetGlobal("print", (Action<string>) Console.WriteLine);

lua.Execute("print('Hello, World!')");

The goal here is to not have to re-invent the wheel by re-defining the entirety of Discord's REST API in Lua here. I could, if it came to it, utilize one of the various Discord Lua libraries, if compatible with 5.4.X, and import it here, but I'd be concerned about security issues with users trying to call functions they shouldn't, etc.

I suggest creating wrapper functions that handle the necessary tasks. This approach introduces an inte…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@QuantumToasted
Comment options

@Quahu
Comment options

Answer selected by QuantumToasted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants