加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

从不同的lua文件调用函数

发布时间:2020-12-14 21:47:24 所属栏目:大数据 来源:网络整理
导读:我在menu.lua中有这个 local db = require "databaseconnection"...local function onEndBtnRelease() local thisandthat = db.getLoggedIn() native.showAlert( "Corona SDK",thisandthat.." teststring",{ "OK" } )end... 这在databaseconnection.lua中 lo
我在menu.lua中有这个

local db = require "databaseconnection"
...
local function onEndBtnRelease()
    local thisandthat = db.getLoggedIn()
    native.showAlert( "Corona SDK",thisandthat.." teststring",{ "OK" } )
end
...

这在databaseconnection.lua中

local function getLoggedIn()
    print("Test")
    --[[...
    ]]--

    return "some data"
end

我唯一想要的是来自getLoggedIn()的String(“some data”),但我得到的只是一个错误:

…coronamenu.lua:51:attempt to call field ‘getLoggedIn’ (a nil value)

永远不会达到外包.
我正在使用Corona SDK和Sublime,来自isLoggedIn()的所需数据来自sqlite-request.我怎样才能达到这个功能?

解决方法

编写模块的一种直接方法是返回一个包含所需函数的表:

local M = {}

function M.getLoggedIn()
    print("Test")
    --...
    return "some data"
end 

return M

请注意,该函数需要是非本地的,或者它是私有的.

有关其他高级方法,请参阅PiL.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读