Skip to content

Request: LuaTable ctor with Array and/or Dictionary parameters #166

Open
@CodeSmile-0000011110110111

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions