syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
Inside Lua how to load lua script?

All interpreted languages allow me load a script from the shell or from inside the session.

In Lua how to load lua script from inside Lua?

I use the dofile() function.

Screendump demo:
dan@hp ~/ks/b/lua $ 
dan@hp ~/ks/b/lua $ 
dan@hp ~/ks/b/lua $ cat hello.lua 
-- hello.lua
print('hello')

-- Auto conversion:
print(1)
print(1.2)
print(1/1.2)
dan@hp ~/ks/b/lua $ 
dan@hp ~/ks/b/lua $ 
dan@hp ~/ks/b/lua $ lua
Lua 5.3.0  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> 
> dofile('hello.lua')
hello
1
1.2
0.83333333333333
> 
> os.exit()
dan@hp ~/ks/b/lua $ 
dan@hp ~/ks/b/lua $ 
dan@hp ~/ks/b/lua $ 

syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me