|
On Sep 8, 2012 8:20 PM, "marbux" <marbux@gmail.com> wrote:
>
> On Sat, Sep 8, 2012 at 4:36 PM, David Given <dg@cowlark.com> wrote:
>
> > I don't believe you can --- my understanding is that labels are pure
> > compile-time constructs and don't contain any runtime state. A jump to
> > an undefined label should produce a compile-time error, not a run-time
>
> Don't know why, but your post sparked the realization that I can do it
> using APIs provided by the particular app Lua is embedded in, the
> NoteCase Pro outliner.
>
> It provides APIs that return the doc ID and node ID of the embedded
> script being executed, as well as an API to get the node content. So
> my script can include a function to fetch its own text as a string,
> then evaluate the string for the presence of the given label after
> concatenating the input string to add the "::" characters for the
> label. Then branch based on the function's boolean return.
>
> I've done something similar recently, extracting the content of the
> first Lua long comment in a script to display the script's
> documentation in the system default browser, when the script is
> selected from a pop-up menu and the user presses the Help button in
> the pop-up. So I've got a lot of confidence this idea will work.
>
> Not as compact as I hoped for, but still avoids having to create a
> table of all the label's texts to test for branching purposes.
>
> Thanks for the nudge, David.
>
> Best regards,
>
> Paul
>
The problem with simple string searching is it fails easily:
if label_exists('foo') then
error("oops, the string '::foo::' occurs in this file")
end
--::bar:: doThingsWeDontNeedRightNow()
if label_exists('bar') then
error("oh no!")
end