main.lua:
start = false
menu = true
function love.draw()
if menu then
dofile("sample\\test1.lua")
else if start then
dofile( "sample\\test2.lua" )
end
end
end
test1.lua
b = 1 + 1
1.怎么获得test1.lua执行的结果呢?比如说b的结果。
2.这样直接调用的话,假如这段代码中有全局变量a,test1.lua中也有全局变量a,后者会把前者给替换掉吗?
先谢谢了。
这样 dofile("test1.lua") 返回的就是 b
2. 这个问题直接试一下就知道了,我试的结果是会.
2010/3/4 Tien <swdgam...@gmail.com>:
2010/3/4 Tien <swdgam...@gmail.com>:
> 那假如我是要调用test1.lua里面的function x怎么办?
>
> --
> 您收到此邮件是因为您订阅了 Google 网上论坛的“Lua中国用户组”论坛。
> 要向此网上论坛发帖,请发送电子邮件至 lua...@googlegroups.com。
> 要取消订阅此网上论坛,请发送电子邮件至 lua_cn+un...@googlegroups.com。
> 若有更多问题,请通过 http://groups.google.com/group/lua_cn?hl=zh-CN 访问此网上论坛。
>
>
On Mar 4, 10:28 pm, Chunlin Zhang <zhangchun...@gmail.com> wrote:
> 那就把 test1.lua 搞成一个模块算了...
>
> 2010/3/4 Tien <swdgame.t...@gmail.com>:
>
>
>
> > 那假如我是要调用test1.lua里面的function x怎么办?
>
> > --
> > 您收到此邮件是因为您订阅了 Google 网上论坛的"Lua中国用户组"论坛。
> > 要向此网上论坛发帖,请发送电子邮件至 lua...@googlegroups.com。
> > 要取消订阅此网上论坛,请发送电子邮件至 lua_cn+un...@googlegroups.com。
> > 若有更多问题,请通过http://groups.google.com/group/lua_cn?hl=zh-CN访问此网上论坛。- Hide quoted text -
>
> - Show quoted text -
f = loadfile("test1.lua")
f("haha")
然后 test1.lua 根据传进的参数 ... 来做处理,这样也许也能达到你的目的.
2010/3/4 Tien <swdgam...@gmail.com>:
test1 = {}
local function test1.func1 ()
...
end
local function test1.func2 ()
...
end
local test1.var1 = 'xxx'
local test1.var2 = 'yyy'
return test1
local test1 = require('test1')
result = test1.func1()
...