lua编译
--2.lua
function test(a,b)
 print(a+b)
end
--3.lua
function testDo(a,b)
 print(a+b)
end
print('DoFile')
f = loadstring('print(123)')
f()
t = loadfile('2.lua') --只是编译
t() --先定义test方法
test(1,2) --3

d = dofile('3.lua') --DoFile,直接编译了,然后定义
testDo(5,3) --8
s = loadfile('5.lua')
print(s)  --nil,dofile会发生错误


在语言运行时,有能力且轻易的执行动态生成的代码,有了这些dofile等才可以将Lua称为一种解析型语言。


首页 我的博客
粤ICP备17103704号