CSharp.lua icon indicating copy to clipboard operation
CSharp.lua copied to clipboard

Unable to consume data from inside of lua. in the .net runtime

Open fusspawn opened this issue 7 years ago • 3 comments

Hey,

Awesome system. Im using it to control the little machines in OpenComputers. a minecraft mod. https://minecraft.curseforge.com/projects/opencomputers

the only thing I really lack is the ability to interact with the already exsiting code in the Lua runtime.

Ideally id want to be able to do something like

LuaRuntime.Execute("_G["gpu"] = require("component").gpu") dynamic gpu = LuaRuntime.GetGlobal("gpu") gpu.fill(.....) <- access existing lua methods.

Being able to execute raw lua can be done already via your /* --[[]]-- */ system. but there's no way to get stuff "out of lua." and into the .net runtime.

Any known work arounds to doing something like this?

fusspawn avatar Jan 30 '19 16:01 fusspawn

Thanks for your use you can put the code into another dll, reference it through the command-line parameter "-l" and complete the compilation

yanghuan avatar Jan 31 '19 03:01 yanghuan

Thanks. combined with the xml templates I got that working. However.. How do you deal with lua functions returning multiple values.

I tried using typed tuples

Tuple<int, int> blah = SomePreexistingLuaFuncThatReturnsMultipleValues();

and value tuples.

(int, int) blah = SomePreexistingLuaFuncThatReturnsMultipleValues();

Both actually compiled fine and produced decent lua. (Which amazed me. Good work!) however it treats it as a single return value and uses indexing into that object.

so that:

    public class Gpu
    {
        public dynamic Aquire()
        {
#if __CSharpLua__
                  /*
                  [[
                    gpu = require("component").gpu
                  ]]*/  
#endif

            return G.Get("gpu");
        }
    }



main:

             var Gpu = new Gpu().Aquire();
            Gpu.setForeground(0x00FF00); //Works fine.
            (int, int) Resolution = Gpu.maxResolution(); //Lua function returning multiple values.
            Gpu.fill(1, 1, Resolution.Item1, Resolution.Item2, "#");

where G.Get is templated to return _G[name]

becomes:

  local Resolution = Gpu.maxResolution() -- Gets treated as a table. not multiple return
   Gpu.fill(1, 1, Resolution[1], Resolution[2], "#") 

Is there a way to handle this properly or do I need to wrap any function that returns multiple values so they return tables instead so that tuples work?

fusspawn avatar Feb 01 '19 01:02 fusspawn

out parameter will putout be return value, you can use out or ref instead

yanghuan avatar Feb 01 '19 14:02 yanghuan