lua-users home
lua-l archive

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


Thanks for the reply.
I created 2 scripts as you said. I kept both the scripts in the same directory and executed the script in Interactive mode. I am getting an execption
"module 'myfuns.lua' not found:
    no field package.preload['myfuns']
    no file '.\myfuns.lua'
    no file 'C:\Program Files (x86)\Lua\5.1\lua\myfuns.lua'
    no file 'C:\Program Files (x86)\Lua\5.1\lua\myfuns\init.lua'
    no file 'C:\Program Files (x86)\Lua\5.1\myfuns.lua'
    no file 'C:\Program Files (x86)\Lua\5.1\myfuns\init.lua'
    no file 'C:\Program Files (x86)\Lua\5.1\lua\myfuns.luac'
    no file '.\myfuns.dll'
    no file '.\myfuns51.dll'
    no file 'C:\Program Files (x86)\Lua\5.1\myfuns.dll'". Please give me suggestion


On Tue, May 7, 2013 at 2:40 PM, steve donovan <steve.j.donovan@gmail.com> wrote:
If a script defines some functions like so

-- myfuns.lua
function answer()
  return 42
end

then we can load it into another script:

dofile('myfuns.lua')
print(answer())

or (better) use require:

require('myfuns')
print(answer())

Then (a) it will not constantly reload the file each time it is required and (b) myfuns.lua can be put on your Lua module path

See the Unofficial FAQ:  http://www.luafaq.org/#T1.19