lua-users home
lua-l archive

Re: Lua round-trip?

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


If you retain the original code block, you could append code that replaces the values you need updated before returning it.

But I don't know whether it's acceptable for your usecase

Thijs



-------- Oorspronkelijk bericht --------
Van: Marc Lepage <mlepage@antimeta.com>
Datum:
Aan: Lua mailing list <lua-l@lists.lua.org>
Onderwerp: Lua round-trip?


Hi, suppose I have a file containing data like:

return {

{
name='foo',
val=42,
_onA_ = function(x)
return doSomething(x)
end,
},

{
name='bar',
val=123,
_onA_ = function(x)
return doSomethingElse(x)
end,
_onB_ = function(x)
return doAnotherThing(x)
end,
},

}


I want to read in the file, manipulate some of the members (like name, val), and then write it out again. But I want to preserve the functions (onA, onB) as they are.

Any tips for how to do this?

I guess I can easily write out the data structures and known members by just writing them out (since I know them) and then try to grab the raw text of the functions from the original input file and write that out in the appropriate place. Is that a good idea? Maybe the debug library can help?

Suggestions?

AltStyle によって変換されたページ (->オリジナル) /