Closed joelverhagen closed 10 months ago
It seems to happen with a List<Location>
(list of structs) return value to. Example:
namespace Knapcode.FactorioTools.OilField.Algorithms;
public static class BreadthFirstFinder
{
public static List<Location>? GetShortestPath(Location start, Location goal)
{
Span<Location> neighbors = stackalloc Location[4];
return null;
}
}
public struct Location
{
public int X;
}
Generated Lua:
-- Generated by CSharp.lua Compiler
do
local System = System
local ArrayLocation = System.Array(KnapcodeAlgorithms.Location)
local KnapcodeAlgorithms
local SpanLocation
System.import(function (out)
KnapcodeAlgorithms = Knapcode.FactorioTools.OilField.Algorithms
SpanLocation = System.Span(KnapcodeAlgorithms.Location)
end)
System.namespace("Knapcode.FactorioTools.OilField.Algorithms", function (namespace)
namespace.class("BreadthFirstFinder", function (namespace)
local GetShortestPath
GetShortestPath = function (start, goal)
local neighbors = SpanLocation(ArrayLocation(4))
return nil
end
return {
GetShortestPath = GetShortestPath
}
end)
namespace.struct("Location", function (namespace)
return {
X = 0
}
end)
end)
end
System.init({
types = {
"Knapcode.FactorioTools.OilField.Algorithms.BreadthFirstFinder",
"Knapcode.FactorioTools.OilField.Algorithms.Location"
}
})
I wonder if my PR https://github.com/yanghuan/CSharp.lua/pull/452 is broken.
I have worked around the problem by not using stackalloc
in my C# and just initializing the array on the heap.
Repro:
Generated Lua:
Error when calling the Lua: