Tag: lua

推Lua表

我在C中创建了一个Lua表,但我不确定如何将该表推到堆栈的顶部,这样我就可以将它传递给Lua函数了。 有谁知道如何做到这一点? 这是我目前的代码: lua_createtable(state, libraries.size(), 0); int table_index = lua_gettop(state); for (int i = 0; i < libraries.size(); i++) { lua_pushstring(state, libraries[i].c_str()); lua_rawseti(state, table_index, i + 1); } lua_settable(state, -3); [ Push other things ] [ Call function ]

lua函数的警报消息

我有以下代码: lua_getglobal(L, “lgd”); lua_getfield(L, -1, “value_pos_x”); cr->value_pos_x = lua_tointeger(L, -1); if (!lua_isinteger(L, -1)) printf(“value_pos_x allows only numbers;”); lua_getfield(L, -2, “value_pos_y”); cr->value_pos_y = lua_tointeger(L, -1); if (!lua_isinteger(L, -1)) printf(“value_pos_y allows only numbers;”); lua_getfield(L, -3, “time”); cr->time = lua_tointeger(L, -1); if (!lua_isinteger(L, -1)) printf(“time allows only numbers;”); 代码完美无缺。 我想知道的问题是,是否可以只保留一条消息并且适用于每个函数,例如: lua_getglobal(L, “lgd”); lua_getfield(L, -1, “value_pos_x”); cr->value_pos_x = lua_tointeger(L, […]

在c-compile期间使用luarocks为lua安装yaml的问题

我有lua,我使用了luarocks。 编辑:在Windows系统上 我从v202-3这里下载了luasocket-2.0.2-3.win32-x86.rock文件,成功安装了luasocket。 它是一个旧版本,但它的工作原理。 但是现在我需要安装yaml所以我可以使用yaml文件。 现在我被迫使用* .src.rock文件或.rockspec文件进行安装。 我试过了: luarocks install yaml ,它给出: D:\user\workspace\_lua>luarocks install yaml Warning: Failed searching manifest: Failed fetching manifest for https://luarocks.org – Failed downloading https://luarocks.org/manifest – C:\Users\user\AppData\Local/LuaRocks/Cache/https___luarocks.org/manifest Warning: Failed searching manifest: Failed fetching manifest for https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/ – Failed downloading https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/manifest – C:\Users\user\AppData\Local/LuaRocks/Cache/https___raw.githubusercontent.com_rocks-moonscript-org_moonrocks-mirror_master_/manifest Warning: Failed searching manifest: Failed fetching manifest for http://luafr.org/moonrocks/ – […]

将C校验和函数转换为Lua

我正在编写一个脚本,允许我的主机设备将数据文件发送到从设备。 从站需要进行校验和计算,并在发送文件之前添加到我的请求的末尾。 我的问题是,我不仅对编程很新,而且还在努力完全掌握位操作。 我目前在一个Java类中,所以校验和function所以部分函数确实有一个熟悉的格式,但由于我仍然在用比特和位库弄乱我的头,我在将提供的校验和函数转换为Lua中。 在C中提供函数之前,首先将该函数描述如下: Initialise the checksum as FFFF(hex). For each byte Checksum = Checksum XOR (current Byte) For I = 0 to 7 If ((Checksum AND 1)=0) Checksum = Right_Bit_Shift Checksum 1 bit Else Checksum = (Right_Bit_Shift Checksum 1 bit) XOR A001(hex) Next I Next Byte 以下是用C编写的示例: /* *Routine CRC takes a data […]

在高山图像上构建lua-openssl时未定义引用“strerror_s”

我正试图像lua-openssl一样建立一个开放式的高山图像 FROM openresty/openresty:alpine-fat # Set the version ENV RESTY_CONFIG_OPTIONS_MORE “–with-ngx_http_ssl_module” EXPOSE 80 EXPOSE 443 RUN ls /usr/local/openresty/nginx/logs COPY lualib /usr/local/openresty/nginx/lualib RUN chown -R nobody:root /usr/local/openresty/nginx/lualib RUN apk add –update \ openssl openssl-dev \ lua5.3 luajit-dev lua-socket \ git RUN git clone https://github.com/zhaozg/lua-openssl.git /usr/local/lua-openssl; \ cd /usr/local/lua-openssl; \ git checkout e923252b28cff43add6382853cc85ed888c4474b; \ make 但我得到下面的那个和很多这样的错误: /usr/local/lua-openssl/deps/lua-compat/c-api/compat-5.3.c:74:对strerror_s’ ./libopenssl.a(cms.o): […]

我是否正确地从C函数中读取嵌套的lua表作为参数?

我将用C语言实现一个函数,它将由Lua脚本调用。 这个函数应该接收一个lua表(甚至包含一个数组)作为参数,所以我应该读取表中的字段。我试着像下面这样做,但是当我运行它时我的函数崩溃了。 任何人都可以帮助我找到问题吗? /* function findImage(options) imagePath = options.imagePath fuzzy = options.fuzzy ignoreColors = options.ignoreColor; … end Call Example: findImage { imagePath=”/var/image.png”, fuzzy=0.5, ignoreColors={ 0xffffff, 0x0000ff, 0x2b2b2b } } */ static int findImgProxy(lua_State *L) { lua_settop(L, 1); luaL_checktype(L, 1, LUA_TTABLE); lua_getfield(L, -1, “imagePath”); lua_getfield(L, -2, “fuzzy”); lua_getfield(L, -3, “ignoreColors”); const char *imagePath = luaL_checkstring(L, -3); […]

在l中嵌入lua代码

我试图遵循这里给出的关于将lua嵌入到C中的besic指南。我将代码逐字复制到我自己的embed.c文件中并执行列出的确切编译器命令: cc -o embed embed.c \ -I/usr/local/include \ -L/usr/local/lib \ -llua -llualib 我收到错误: embed.c:19:14: error: invalid storage class for function ‘openlualibs’ 之后我将函数移到main之外,再次编译,得到: /usr/bin/ld: cannot find -llualib 我不知道为什么我不能编译这个。 lua安装正确。 还有其他人遇到过这些问题吗? 如果这是一个糟糕的教程,请随意简单地指导我一个击球手。

Lua – 为什么C函数作为userdata返回?

我正在为我的引擎开发游戏脚本,并使用metatable将函数从表(存储自定义函数和播放器数据)重定向到userdata对象(这是我的Player类的主要实现),以便用户可以用self来指代两者。 这就是我在Player类中使用C#进行绑定的方法: state.NewTable(“Player”); // Create Player wrapper table state[“Player.data”] = this; // Bind Player.data to the Player class state.NewTable(“mt”); // Create temp table for metatable state.DoString(@”mt.__index = function(self,key) local k = self.data[key] if key == ‘data’ or not k then return rawget(self, key) elseif type(k) ~= ‘function’ then print(type(k)) print(k) return k else return function(…) […]

如何在不执行脚本的情况下加载lua变量和函数?

我看到的每个地方,我都看到从许多C线程运行lua脚本的最佳实践是为每个线程使用不同的lua_State。 从这一点开始,请使用以下脚本: local var1 local var2 — etc. function onClick(x, y) — Process mouse click end function onKey(k) — Process key stroke end — Do some stuff while(true) do — Do some stuff end 其中onClick和onKey是Win32应用程序调用的回调函数。 这些函数逐个C线程调用。 其中每一个都拥有自己的lua_State。 因此,总共有3个C线程(和3个lua_States):一个用于上述每个函数,最后一个用于运行不是函数的所有东西(while循环和东西)。 因此,由于Lua只能在lua_dofile和lua_dofile执行所有操作之后才能看到脚本中的内容,如何在不执行整个脚本的情况下调用这些函数? 我只想让一个线程卡在无限循环中; 其他人必须等待回调函数。

PlaneMylinder中有一个选项可以扭曲imageMagick来制作像下面的图像吗?

当我使用Plane2Cylinder失真时,我得到了如下图像。 但我希望效果像第二张图像。 请仔细检查我的代码。 local nelem = 1 — number of args local arg = ffi.new(“const double[?]”, nelem, {100}) — local methos = ffi.new(“const int”, 15) return handle_result(self, lib.MagickDistortImage(self.wand,13, nelem, arg, 1)) ffi.cdef([[ typedef void MagickWand; typedef void PixelWand; MagickBooleanType MagickDistortImage(MagickWand *wand, DistortMethod method, const size_t, const double *args, const MagickBooleanType bestfit); 更新:对于fred的脚本我使用下面的命令 bash -x ./cylinderize.sh […]