【发布时间】:2017-11-12 13:15:26
【问题描述】:
我无法在 Lua 中加载需要另一个模块的模块。我已经尝试阅读官方文档,但我仍然不清楚。使用 package.path 和 require 的组合加载单个模块可以正常工作。但是对 require 的嵌套调用失败并产生错误:函数中的 C 级别过多(限制为 200)
我有一个项目结构如下:
./exeDir: 包含 tBig.lua
./utils:包含 pkgBig.lua 和 pkgSmall.lua
pkgSmall.lua
-- this module is loaded later in pkgBig.lua
local function toto(s)
print('Toto says: ' .. s)
end
local function dummy()
print('Dummy')
end
pkgSmall =
{
toto = toto,
dummy = dummy,
}
return pkgSmall
pkgBig.lua
local myPkg = require 'pkgSmall'
local function titi(s)
print('Titi says (followed by dummy): ' .. s)
myPkg.dummy()
end
local function fifi()
print('Calling toto from fifi...')
myPkg.toto('FiFi called me')
end
pkgBig =
{
titi = titi,
fifi = fifi,
}
return pkgBig
主脚本:
tBig.lua
package.path = package.path .. ';' .. 'pathToUtils/pkgBig.lua'
local big = require 'pkgBig'
big.titi(' called from main')
big.fifi(' pkgSmall test')
调用此脚本会产生“太多 C 级别...”错误。
【问题讨论】:
标签: lua