Function 从不同的lua文件调用函数

Function 从不同的lua文件调用函数,function,module,lua,coronasdk,Function,Module,Lua,Coronasdk,我在菜单上有这个 local db = require "databaseconnection" ... local function onEndBtnRelease() local thisandthat = db.getLoggedIn() native.showAlert( "Corona SDK", thisandthat.." teststring", { "OK" } ) end ... 这在databaseconnection.lua中 local functio

我在菜单上有这个

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 
module(..., package.seeall)
我唯一想要的是
getLoggedIn()
中的字符串(
“某些数据”
),但我得到的只是一个错误:

…\corona\menu.lua:51:尝试调用字段“getLoggedIn”(一个nil值)

永远达不到输出。
我正在开发Corona SDK和Sublime,来自
isLoggedIn()
的所需数据来自一个sqlite请求。如何访问该函数?

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

local M = {}

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

return M
请注意,该函数必须是非本地的,否则它将是私有的


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

您也可以使用seal类

只需在类顶部的行下方书写(databaseconnection.lua)


然后在main.lua中调用您的函数,它将返回您想要的相同值。

您也可以通过这种方式获取数据

在menu.lua文件中需要(“databaseconnection”),并调用get login函数

本地abc=getLoggedIn()

印刷(abc)