Using nlua to read local variable and write changes?

24 views Asked by At

I have following lua file

test = "test"
local fid = {
    ["dir1"] = {
     ["val1"] = 0
    }
}
return fid

I need to read it into C# object, manipulate it and then save it back into original file.

Issue 1: i cannot access fid variable.

Lua l = new Lua();
l.DoFile("C:\\file.lua");
String t = (String)l["test"]; //this works fine
LuaTable d;
d = l.GetTable("fid"); //this comes back null
object x;
x = (Object)l["fid"]; //also comes back null

If i remove "local" from declaration - i can read it fine. How do I read "local" variable ?

Issue 2: If i make changes to variables above (for example changing test string ) - how do I persist those changes ? I was unable to find any clues anywhere. I have a feeling I'm going about this wrong way - i can't be a first guy trying to manipulate lua config files using C#..

Any hints welcome. Thank you.

0

There are 0 answers