[C# and Lua in the same resource] Is there any way to call C# functions from lua within the same resource?

Imagine I have a resource HelloWorldTest which contains both LUA and C# code.

If I have a HelloWorld class in C#, and I want to create a new instance of that HelloWorld class in LUA, how would I do this? In my perfect world, it would be like create HelloWorld(in, put, args) in LUA.

Further, would I then be able to call the internal or even just public methods from the in-resource, so like HelloWorld.GetValue() in LUA calling public int GetValue() written in C#.

Sorry for blurb, I am multitasking.

What am I missing here?

External resource calls using exports don’t export methods or even null fields from C# into LUA.

Reason I’m asking is because C# has a leg up in some areas and LUA in others, so I want to get greedy and have both cakes.

(Example code from extra-resource calling)
example.zip (1.4 MB)

Example of running the resources

Hmmm - I’m sure there are way more creative ways than this, but it may be worth invoking a server script since there are ways to do it from both types of client files…

…I’m asking for the server. These are server-only resources I need to do cross-language transfers with

Ah, then what you’re looking for may be possible using the specific I/O functionality of each language.

Using Lua and Csharp, you can read from and write to files:
LuaIO
CSharp

I’d recommend writing your CSharp and lua to individual files until you’re comfortable enough with how they work comfortably to be able to read and write to the same file…

Once again, I’m sure that the geni (plural of geniuses) on this forum can offer some better, more efficient ways of moving forward on this, but hopefully this will give you at least some momentum!

Yeah, as much as I love some good old fashioned socketwork, what I’m asking for is a way that I can more or less use reflection to just magic over the HelloWorld object instance to LUA so I could call its public methods; maintaining respect the getters and setters with access modifiers, but it seems I’m dreaming at this point, sandboxing and silverlight aside.

Hahaha hell nah man!
There’s always a million ways to do things - I’m sure there’s a way to do it! This is just one more method that you’re not going to use and that’s okay!
Hopefully someone here can throw some input in soon! <3

Can you explain what you mean by socketwork, in regards to IO?

I’m now tackling this issue. I also want to call a function in a C# resource from a lua resource. I was building a Lua resource but need to use the task sequencing natives that only work in C#. Hoping I can call a function in C# in my lua resource where I would’ve put the task sequencing if it worked correctly.

I dont see how IO could solve this problem? How would the C# resource know when to check the IO file to read a command issued from the Lua resource. Surely you cant just re open file streams in a loop in both resources (also dont think you can have two filestreams open to same file synchronously)

Update, using exports worked.
In my C# files I create an export like this:

Exports.Add(“FunctionName”, new Action(FunctionName));

This line goes within the class initializer.

Then within my lua files I can do exports[“resourceName”]:FunctionName(“args”)

I think you might be a bit off-topic.

I was referencing the ability to transfer classes between languages, keeping the method calls intact.

It’s been a while, but if I recall correctly, for example;

public HelloWorld {
    private string sep = "";
    public HelloWorld() {
    }
    public HelloWorld(string seperator) {
        this.sep = seperator;
    }
    public print() {
        Console.WriteLine($"Hello {this.sep} world!");
    }
}
local hw = HelloWorld("C#")
hw:print() --"Hello C# world!"

or

local class =  {
    __call() = function(sep)
        return class.new(sep)
    end,
    new = function(sep)
        local o = {}
        if sep then
            o.seperator = sep
        end

        return setmetatable(o, class)
    end,
    print = function(self)
        print("Hello ".. self.sep or "" .. "world!")
    end
}
dynamic luaclass = new class("Lua");
luaclass.print(); //Hello Lua world!

In theory, you could probably create wrappers and exports, but that gets messy, fast. On first thought in a while, you’d have to subclass the data into odd types and stringify lua metatable functions. You could probably build a whole reusable thing for it, but I’d prefer just wait for the C#v2 mono and do everything in that from the ground up as it stands.