我正在寻找每个实际需要运行lua脚本所需的库,该脚本需要火炬库。
test.lua
#!/usr/bin/env lua
print "Welcome to LUA"
print('_VERSION = ' .. _VERSION)
require("nn") -- this loads torch nn libraries to be further used in the code
print "Load pass"
输出
Welcome to LUA
_VERSION = Lua 5.1
Load pass
当我用
lld
我在NeoVim中的配置有问题。在我设法使LSP (使用lspconfig)工作后,我注意到我为NERDTree和其他扩展(望远镜)实现的密钥不起作用。但是,当我从Nerdtree执行函数时,它就能工作了。因此,这个问题可能会出现一些键绑定的错误配置。
我为lspconfig设置的配置是:
lua << EOF
local nvim_lsp = require('lspconfig')
-- Use an on_attach function to only map the following keys
-- after the language server a
我正在研究如何在lua字符串(双括号)中嵌入lua函数。我只想详细解释一下我的情况:
example.lua:
function my_message(msg)
return "Your message: " + msg
end
function makeString()
page = [[
<html>
<body>
<!--
I want to call my_message(..) lua function and embed the value here.
我试图使用多个过滤器来查询国际航空公司,并参考了这个。
我能够根据给定的lua脚本查询aerospike的一个过滤器参数,但当必须传递超过2个筛选参数(例如,传递两个以上的参数,例如年龄、性别和密码)时,我可以使用lua脚本。
这是我第一次和lua在一起。
Lua脚本:
local function map_profile(record)
return map {name=record.name, password=record.password}
end
function check_password(stream,password)
local function filter_pass
我试图向Lua脚本提供一个整数列表,并对它们进行迭代。
我得到的错误是:
test.lua:12: bad argument #1 to 'pairs' (table expected, got userdata) stack traceback: [C]: in function 'pairs' test.lua:12: in main chunk
正在使用的C++代码:
#include <sol.hpp>
struct Test {
std::vector<int> a;
};
int m
我正在用Lua/love2d编写一个小的RPG游戏引擎,我需要将一个文件解析成一个2d数组,但它不能工作,而且我收到了错误...
main.lua:
local fmap = love.filesystem.read("map.txt")
map = {}
for c in fmap:gmatch(".") do
if c == "\n" then
y = 0
x = x + 1
else
map[x][y] = c -- this won't work
y
我已经将Lua嵌入到我的C应用程序中,并试图通过以下方法了解为什么在C代码中创建了一个表:
lua_createtable(L, 0, numObjects);
返回Lua后,当我调用以下命令时,会产生一个零的结果:
print("Num entries", table.getn(data))
(其中“数据”是lua_createtable在上面创建的表)
表中显然有数据,因为我可以通过以下方式遍历每个条目(string : userdata)对:
for key, val in pairs(data) do
...
end
但是为什么table.getn(数据)返回零呢?
我正在使用,并以这样的方式在AS3代码中设置一个全局变量:
_lua.setGlobal("map", _map);
_map是一个具有以下函数的对象:
public function get x():int
{
return 10;
}
如果我想在Lua做这样的事
local a = map.x + 1
我得到以下错误:
Lua script failed: luaDoString:21: attempt to perform arithmetic on field 'x' (a table value)
有人知道为什么会这样吗,我怎么能修好它呢?
编
比如说,aerospike数据库有如下记录的数据
将名称空间设为employee
name age characteristics
sachin 25 MAP('{"weight":70, "height":25}')
现在,我希望通过lua脚本为employee名称空间中的所有记录更改高度值。
我已经尝试更改正常数据类型的bin,如下所示,即我尝试更改年龄,如下所示:
function changeAgeOfEmployee(rec)
if not aerospike:exists(rec) then
error (
在Aerospike客户机中,可以通过MapOrder属性(如MapOrder.KEY_ORDERED或MapOrder.KEY_VALUE_ORDERED )创建排序映射。
在Lua中,指出了创建CDT映射的几种方法,但没有一种方法允许指定映射顺序:
local m1 = map() -- create map
local m2 = map.create(100) -- create with initial size
local m3 = map { a = 1, b = 2, c = 3 } -- create with
我正在使用lua在C++/SDL中加载我的地图,我在lua中有一个数组来确定瓦片图像的位置,但我不知道如何将它转换到C++中的数组中,我已经寻找了一个解释,但它们都处理it,并且lua文件只有1个数组,并且由于某种原因,代码不能工作,这可能是一个愚蠢的问题,但是是的
代码如下:
Map.lua
Tile = {}
--opens file and reads it
local file = io.open("../Maps/Map.txt")
local n = 0
while(n <= 494) do
Tile[n] = file:re
我是lua的新手,所以如果这个问题太基本了,请原谅。我想知道是否有一个好方法来检查一个值是否不在lua表中。类似于: if 5 ~= t[1] or 5 ~= t[2] or 5 ~= t[3] ... then end 但没那么愚蠢。 这 for i,v in ipairs(t) do
if 5 ~= v then
end
end 实际上并不起作用,因为我想检查它是否没有出现在表中的任何地方,而不是它是否等于任何给定值。 到目前为止,我能想到的唯一可行的解决方案可能是 check = 0
for i,v in ipairs(t) do
if 5 == v then
这里是游戏开发和Lua的新手。我正在制作一个平台,我希望能够在角色与某个物体发生碰撞时重新启动游戏,并在此之前显示标题。我也想把角色的位置重置回0,0,但我不知道怎么做。
我创建了一个名为WIN的全局变量,如果角色与对象发生碰撞,该变量将设置为true,这是可行的,但随后进入我的love.draw()函数,我将获得以下内容:
function love.draw()
-- begin virtual resolution drawing
push:apply('start')
-- clear screen using Mario background blue
love.
我遇到了古老的,在Lua中有一个可以包含nil值的数组,我想用nil值解压该数组;这似乎是不可能的。这个逻辑的替代方案是什么?
下面是我尝试运行的代码
function InputSystem:poll(name, ...)
local system = self:findComponent(name)
local values, arr = {...}, {}
for i, v in pairs(values) do
arr[#arr+1] = system[v]
end
--If the first guy is null this does not work
我正在努力将lua程序转换成C++程序,但我遇到了一个障碍,我不知道如何将它转换为C++
function newPool()
local pool = {}
pool.species = {} --imports data from local species = {}
pool.generation = 0
pool.innovation = Outputs
pool.currentSpecies = 1
pool.currentGenome = 1
pool.currentFrame = 0
pool.maxFitness
local pricetagColors = {
[3242] = {255, 0, 255},
[6712] = {255, 255, 0}
}
function getPricetagColor(itemnumber)
local r, g, b = 0, 0, 0
if pricetagColors[itemnumber] then
r, g, b = pricetagColors[itemnumber][1], pricetagColors[itemnumber][2], pricetagColors[itemnumber[3]
我有一套带有下列结构箱的飞机:物品、时间戳、数量、价格、折扣
我正在尝试实现以下等价的SQL
SELECT item, sum(qty), sum(price), sum(discount)
FROM items
WHERE timestamp between 20150101000000 and 20150101235959 GROUP BY item
但是,在执行脚本时,我试图按照lua脚本编写,但我得到了以下错误
错误:(1) AEROSPIKE_ERR_SERVER:"UDF:执行错误2: /opt/aerospike /usr/udf/lua/ggregateByItem.
我正在尝试在Lua中注册一个c++函数。
但是得到这个错误:
CScript.cpp|39|error: argument of type 'int (CScript::)(lua_State*)' does not match 'int (*)(lua_State*)'|
编辑:
int CApp::SetDisplayMode(int Width, int Height, int Depth)
{
this->Screen_Width = Width;
this->Screen_Height = Height;
this-
是否可以在Lua中对多个值执行算术。我在windows 5.1.4中使用Lua。
目前,我必须将多个值放入一个表中,然后解压它们,我希望能够跳过这一步。
有可能。
以下是我目前的情况:
function numsToStr(...)
local nums = {}
for i,v in ipairs({...}) do
nums[i] = v + string.byte('A') - 1
end
return string.char(unpack(nums))
end
我想要的是能够做到这一点
function numsToSt