我想用Lua第三方模块构建nginx.该模块需要Lua库.Lua 5.1安装在我的服务器上.但是当我使用nginx lua模块的路径运行./compile时.抛出错误:
checking for Lua library ... not found
checking for Lua library in /usr/local/ ... not found
checking for Lua library in /usr/pkg/ ... not found
checking for Lua library in /opt/local/ ... not found
checking for Lua library in /usr/local/../lua51/ ... not found
checking for Lua library in /usr/ ... not found
./configure: error: ngx_http_lua_module requires the Lua library.
Run Code Online (Sandbox Code Playgroud)
我尝试通过导出给路径,LUA_LIB=/usr/local/lib/但也没有用.
任何帮助,将不胜感激.
当我尝试在Ubuntu上使用LuaSocket创建一个侦听任何端口的套接字时,套接字的创建失败并显示"权限被拒绝":
require("socket")
server, msg = socket.bind("*", 23)
if not server then print(msg) end
Run Code Online (Sandbox Code Playgroud)
但是,当以超级用户(使用sudo)执行相同的脚本时,服务器的创建工作正常.有没有理由说LuaSocket无法正常创建服务器?我可以做任何事情(在Lua或Ubuntu服务器上),这样就不需要以超级用户身份执行脚本了吗?
我正在尝试将数据库的数据类别的数据值加载到表中以供进一步处理.每个数据类别都应该有自己的表.遗憾的是,数据类别的数量不一致,因DB而异,因此我考虑根据当前数据类别的数量自动创建表:
--categories is a table containing the names of all data categories
for a = 1, #categories, 1 do
temptable..a = {};
end
Run Code Online (Sandbox Code Playgroud)
这当然不起作用,因为Lua尝试将表分配给变量而不是其值.这种方式也不可能进行变量连接.有没有办法让Lua自动创建表格?
我认为lua_settop()的文档很清楚:
void lua_settop(lua_State*L,int index);
接受任何可接受的索引或0,并将堆栈顶部设置为此索引.如果新顶部大于旧顶部,则新元素将填充为nil.如果index为0,则删除所有堆栈元素.
......然而,这段代码:
lua_settop(L, 0);
top = lua_gettop(L);
if (lua_isnoneornil(L, top)) {
printf("Invalid stack (nil)");
}
else {
// WTF?
printf("? %d -> %s", top, lua_typename(L, lua_type(L, top)));
}
Run Code Online (Sandbox Code Playgroud)
产量:
? 0 -> table
Run Code Online (Sandbox Code Playgroud)
是什么赋予了?
如何检查堆栈是否为空?使用(lua_gettop(L)== 0)?
如果是这样,为什么还有一个lua_isnone()调用呢?
我正在从Corona的示例代码中分析Fishies projest,我无法理解该任务.
background = ( backgroundLandscape == background and backgroundPortrait ) or backgroundLandscape
Run Code Online (Sandbox Code Playgroud)
这是完整的代码:
-- Seed randomizer
local seed = os.time();
math.randomseed( seed )
display.setStatusBar( display.HiddenStatusBar )
-- Preload the sound file (theoretically, we should also dispose of it when we are completely done with it)
local soundID = audio.loadSound( "bubble_strong_wav.wav" )
-- Background
local halfW = display.viewableContentWidth / 2
local halfH = display.viewableContentHeight / 2
-- Create a table to store all the fish and register this table as …Run Code Online (Sandbox Code Playgroud) 我只是想知道如何计算lua中2D数组或表中组件的总和.我尝试过搜索,但似乎没有任何明确或简单的方法.
我有一个5x5矩阵,有随机生成的单元格,我想知道在给定时间这些值的总和.
有没有内置到lua中的任何内容,例如sum(矩阵)或sumof(matrix [] []).
提前致谢
我写了一些像这样的lua代码:
local a1 = 1
local a2 = 2
local a3 = 3
local a4 = 3
local a5 = 3
local a6 = 3
local a7 = 3
local a8 = 3
local a9 = 3
local a10 = 3
local a11 = 3
local a12 = 3
local a13 = 3
local a14 = 3
local a15 = 3
local a16 = 3
local a17 = 3
local a18 = 3
local a19 = 3
local a20 = …Run Code Online (Sandbox Code Playgroud) 在我开始之前,我会说我是Lua的初学者,所以可能不知道所有正确的术语,但我会尽力解释我所追求的.
我有一个data包含其他表的table().当data首次创建,它可以具有任何数量的在其内部表(I期望这是1和50之间).
我想将每个表分配给它自己的变量.
如果我知道有多少表,那么这很容易使用table1 = data[1]; table2 = data[2],依此类推.
我已经完成了计数,data以便我知道条目的数量,所以我想要做的是自动创建变量,给它们一个名称并为其分配相应的表.
所以我们说data包含10个表.那么我想变量,创建名为table1,table2,table3等等.table1应该是data[1],table2应该是data[2]等等.
我确定我应该创建一个循环,每次都有一个count=count+1创建附加到变量的数字.
我遇到的问题是我不知道如何创建一个名为'table'+count(table1)的变量.
我如何一起加入2?
我在Lua中有一个在表上运行的函数,重复向表中添加条目:
function DoStuff()
local table = {};
for i = 1, 1000 do
local name, value = GetSomething(i);
if (CheckSomething(name, value))
table[name] = value
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
我知道这很快; Lua有一个很好的哈希表算法.但是现在我需要拆分我的部分功能,所以我可以对它进行单元测试:
function DoStuff()
local table = {};
for i = 1, 1000 do
local name, value = GetSomething(i);
--split out checking so it's testable
table = ParseTheThing(table, name, value);
end;
end;
Run Code Online (Sandbox Code Playgroud)
我知道Lua不支持通过引用传递参数,相反如果我需要向我添加一个项目table,Lua将复制并且我必须返回该副本:
--Core checking function
function ParseTheThing(table, name, value)
if (CheckSomething(name, value))
table[name] = value
end; …Run Code Online (Sandbox Code Playgroud)