Lua中的loadfile、dofile、loadstring、require用法实例
do
localerrorInfo=loadfile("test.lua");--loadcodefile
if(errorInfo==nil)then
print("loadfilefailed");
else
print("loadfilesuccess");
localdoInfo=dofile("test.lua")--compliethefileandexecutethefile
if(doInfo==0)then
print("runfilefailed");
else
print("runfilescuess");
end
end
--locali=0;--itmustbeglobalvar,theloadstringonlycalltheglobalvar i=0; localf=loadstring("i=i+1");
f(); print(i); g=function() i=i+1;--itcancallthelocalandtheglobalvar end g(); print(i); end