You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Request: LuaTable ctor with Array and/or Dictionary parameters #166
For better data-exchange from C# to Lua I would really like to have a LuaTable initializer that I can just pass an array, a dictionary, or both and preferably with internalized LuaValue conversion.
This would be good enough:
LuaValue[] array = ...
var arrayTable = new LuaTable(array);
IDictionary<LuaValue, LuaValue> dict = ...
var dictTable = new LuaTable(dict);
// and both:
var table = new LuaTable(array, dict);
While this would be great:
bool[] boolArray = ...
var arrayTable = new LuaTable(boolArray);
Dictionary<int, SomeUserDataType> userdataDict = ...
var dictTable = new LuaTable(userdataDict);
// and both:
float[] floatArray = ...
Dictionary<string, int> intDict = ...
var table = new LuaTable(floatArray, intDict);
And for best Unity serialization support, since it cannot serialize dictionaries, using two lists for dictionary keys and values to avoid having to first create a dictionary that would then internally get converted to LuaValueDictionary:
ILuaUserData[] array = ...
IEnumerable<string> keys = ...
IEnumerable<int> values = ...
var dictTable = new LuaTable(array, keys, values);
The keys and values enumerables need to have matching lengths.
Again, the types are just for example. Supported LuaValue Types should be automatically converted, otherwise it throws.
changed the title [-]Request: LuaTable ctor with Array or Dictionary or both[/-][+]Request: LuaTable ctor with Array and/or Dictionary parameters[/+]on Jun 8, 2025
It seems sufficient to make the following on your own.
It is not likely to be possible to implement individual case optimization on the part of this library.
Will we be able to do DoFileAsync(script, LuaValue[] args) passing arguments to the script in 0.5?
I had a discussion with nuskey about it before, but we finally decided not to support it, because it is not supported in clua and can be handled by loadfile(path)(args).
CodeSmile-0000011110110111 commented on Jun 13, 2025
Activity
[-]Request: LuaTable ctor with Array or Dictionary or both[/-][+]Request: LuaTable ctor with Array and/or Dictionary parameters[/+]akeit0 commentedon Jun 8, 2025
It seems sufficient to make the following on your own.
It is not likely to be possible to implement individual case optimization on the part of this library.
CodeSmile-0000011110110111 commentedon Jun 9, 2025
That's what I've done so far. Would be nice to have this as an extension method in the framework so that this has a common API.
CodeSmile-0000011110110111 commentedon Jun 11, 2025
Will we be able to do
DoFileAsync(script, LuaValue[] args)passing arguments to the script in 0.5?So that outside any function we can get these as "command line" arguments:
local scriptArgs = {...}akeit0 commentedon Jun 12, 2025
I had a discussion with nuskey about it before, but we finally decided not to support it, because it is not supported in clua and can be handled by loadfile(path)(args).
CodeSmile-0000011110110111 commentedon Jun 13, 2025
In case someone has the same need, I went with this solution just passing a single LuaTable as argument.
These are the necessary extension methods:
I can then call Dostring like this:
And in the Lua script I use the arguments like so: