lua-users home
lua-l archive

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


There are several ways of executing a bit of Lua code inside of Lua. If
the code is in a file, you can use the  "dofile" function as described
by lhf.

If you have the script as a lua string, then you can execute it using
loadstring. Something like this: (Note: Lua 5.0 code)

    local code = "x = 10"
    local f = loadstring(x)
    -- at this point the code hasn't executed, to do
    -- that, execute f as a function.
    f()
    print(x)

This should print out the value of x as 10.

Hope this helps.

  - Tom
>>> rogerdv@softhome.net 05/09/03 04:34 AM >>>
El Jueves, 8 de Mayo de 2003 10:38 PM, Luiz Henrique de Figueiredo
escribi¾:
> >How can i execute a simple piece of lua code  from another lua
script?
>
> I'm not sure what you mean. If script A wants to run script B, try
> dofile"B" inside A. If A wants to run a function defined in B, first
> dofile"B" before or while running A and then call the function.
What i need (now) is the first case. I need to run a couple of lines 
containing some asignments.

-- 
Roger D. Vargas
ICQ: 117641572
Linux user: 180787
* Tanto si piensas que puedes, como si piensas que no puedes, tienes
raz¾n *
Henry Ford