Reputation: 1325
I know its possible to pass Json data into c# object, but is it possible to do with lua?
Lets say this is my lua code:
data:extend(
{
{
type = "technology",
localised_name = {"technology-name.logistic-science-pack"},
effects =
{
{
type = "unlock-recipe",
recipe = "logistic-science-pack"
}
},
unit =
{
count = 75,
ingredients = {{"automation-science-pack", 1}},
time = 5
},
},
{
type = "technology",
localised_name = {"technology-name.chemical-science-pack"},
effects =
{
{
type = "unlock-recipe",
recipe = "chemical-science-pack"
}
},
unit =
{
count = 75,
ingredients =
{
{"automation-science-pack", 1},
{"logistic-science-pack", 1}
},
time = 10
},
prerequisites = {"advanced-electronics", "sulfur-processing"},
},
}
)
Yes, its a list of same object. This code, alto shortened, is from a game that I took as an example (and what 'm using to play around with lua).
Would it be possible to convert this lua code/data into a c# object or at least into Json so later you can convert Json into c# object?
I been trying to find the answer on the net, but all I'm finding is how to use lua for scrips or writing a script to create and store c# objects. Nothing what im looking for.
Also what nuGet package should I get or would you recommend? It seems there a lot of em on nuGet package browser (VS) and over the net there are a lot of different opinions.
Thank you in advance!
Upvotes: 0
Views: 243
Reputation: 2531
If you use lua C# engine (like Nlua), you can get object direcly from this engine. If you name lua state as state
it may be returned by state.DoString ("return data")[0]
.
If you connect only to C#, you have to use serializing. JSON is good documented and mature format and have many lua libraries. My personal best is dkjson.
Upvotes: 2