lua-users home
lua-l archive

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


On Tue, Jul 27, 1999 at 06:53:24AM -0300, Luiz Henrique de Figueiredo wrote:
> >From lua-l@tecgraf.puc-rio.br Tue Jul 27 01:54:42 1999
> >From: Pablo Saldo <ec4pas@super.furg.br>

> >Is there a way to retrieve the code in a passive way, without executing any
> >code?
> 
> I'm not sure what you mean here.
> lua_dostring always executes the string it gets, but this execution can be
> simply the definition of some functions, eg:

I'll restate the question as: If we define lua_dostring as:

function lua_dostring(a_string)
  a_block = lua_parsestring(a_string)
  lua_doblock(a_block)
end

How do we do "lua_parsestring" and "lua_doblock"?

I'm guessing that the closest you can get is to build the
tokenizer/compiler stuff in as a function, "compile" from source to
bytecodes first, and then "lua_dostring" the bytecodes as necessary.

Although I must admit that I've always disliked the whole
"lua_dostring()" interface. I'd prefer to prevent any side-effects as
a result of just bringing in a module. As a result, I use my own Perl
style 'require()' function which keeps track of module loads, and from
which I have always intended to enforce some concept of
namespaces/context. (i.e. make global variables "module-global" only)

-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske@chat.net