lua-users home
lua-l archive

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


Hi!

Maybe a stupid idea, but you could concatenate all code strings and then "loadstring(strings)()" them?

- - -
loadstring([[
print("starting")
]]
.. io.input("oneVar.lu"):read("*a")
.. [[
print(x)
print("the end")
]])()
- - -

Performance issues put apart. This can be syntaxsugarified with args and an "include(filename)" function instead of io.input...

Regards,

    Jorge-León


On 10/18/11 14:11, Patrick Mc(avery wrote:
I'm apologizing in advance for the first negative toned email I have
sent to this list.

I really respect Luiz and Roberto and there have been a lot of helpful
people on this list but Lua's glow is dimming for me. It's tiresome
watching this endless battle between Lua titans over module while
lua-peasants like me seem to be without basic tools.

I've been on the list for about 2 years, read PIL cover-to-cover >5X
times bought all the other Lua books yet I had to ask another list
member how to include code without module or dofile. I think every
newcomer to the language would expect this to work:

(file oneVar.lua)
local x = 1

(file simpleTest.lua)
print("starting")
dofile("oneVar.lua")
print(x)
print("the end")

Yet the results are:

(results)
starting
nil
the end

I don't want to have to pack x into a table and return it, on the
other end I don't want to have to define a new local variable to
receive the payload from require. PHP is a poorly constructed language
but include just switches execution from one file to the other and
then goes back to the first, it's dead simple to pick this up. Please
consider the little people down here that don't have code that will be
published-Patrick