LuaSharp icon indicating copy to clipboard operation
LuaSharp copied to clipboard

LuaTable to List?

Open dsblank opened this issue 14 years ago • 1 comments

How can one get a LuaTable into a C# list?

I have tried variations of:

public static System.Collections.Generic.List ToList(LuaSharp.LuaTable table) { System.Collections.Generic.List list = new System.Collections.Generic.List(); System.Collections.Generic.KeyValuePair<object,object> pair in table) { list.Add(pair.Key.ToString()); } return list; }

but, I get a Mono crash when I try to generate the KeyValue Enumerator.

Ideas?

-Doug

dsblank avatar Aug 21 '11 15:08 dsblank

Code was a bit wrong:

public static System.Collections.Generic.List ToList(LuaSharp.LuaTable table) {
    System.Collections.Generic.List list = new System.Collections.Generic.List();
    foreach(System.Collections.Generic.KeyValuePair pair in table) {
        list.Add(pair.Key.ToString());
    }
    return list;
}

dsblank avatar Aug 21 '11 15:08 dsblank