lua-users home
lua-l archive

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


Thanks guys.

Another approach I could do is to require some kind of comment demarcation on the extra parts, so they can be preserved. It's just I'd like to avoid that if possible.

What I've got is a description of things with properties and handlers, I want to load it in my editor (I'm writing), edit the properties, and save it back, but keep the handlers (which are functions).

I'm going to take a crack at some kind of solution this weekend, so keep the ideas flowing.


On Fri, Nov 8, 2013 at 1:03 PM, Paul Merrell <marbux@gmail.com> wrote:
On Fri, Nov 8, 2013 at 8:29 AM, Marc Lepage <mlepage@antimeta.com> wrote:

> 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?

I may be misunderstanding what you're after, but if you rewrite your
script so that each part you want to keep unchanged is assigned to its
own variable in long string format, e.g.,

local bas = [[
_onA_ = function(x)
            return doSomething(x)
        end]]

... in Lua 5.2 you can execute the value stored in bas using load.

And you'd still have the variable name and its value to concatenate
into the string for the new file unchanged.

I'm not certain how to do this in Lua 5.1; I recall that load's
behavior was changed somewhat in 5.2.

Paul

--
[Notice not included in the above original message:  The U.S. National
Security Agency neither confirms nor denies that it intercepted this
message.]