lua

Luajit equivalent for string.pack and string.unpack?

亡梦爱人 提交于 2021-02-10 14:18:56
问题 I need to save a list of lua float nubers in byte form and attach that to a string. I know string.pack exists for Lua 5.3 but I'm limited to Luajit. I'm not too familiar with FFI and I'd appreciate help on using it if it has a solution ( using tostring(number) just uses way too many bytes for numbers and memory is limited ) Basically, I need a way to get a binary string packed form of a list of numbers (floats for now), using Luajit, and be able to store it in a string & concat that string to

Lua: How do I replace two or more repeating “?” characters with an empty string?

守給你的承諾、 提交于 2021-02-10 14:17:47
问题 I've tried something like the following: local str = "???" string.gsub(str, "(??)*", "") but it removes all '?' characters. I'd like single '?' not replaced but more than one '?' replaced with an empty string. Eg: "?" = not replaced "??" = replaced "???" = replaced Any help would be greatly appreciated. 回答1: Question marks are magic in Lua patterns: they mean 0 or 1 occurrence of the previous class. Lua escapes magic characters in patterns with the % character. The correct pattern for your

TCP load balancing and rerouting based on first few bytes

痴心易碎 提交于 2021-02-09 14:27:32
问题 I have made a game where clients connect to a central server with TCP connection. In the first 6 bytes I send the version number "00.00.01" of the client protocol. Based on this version I want to route/proxy the tcp connection to different servers where different version of the game will be running. Basically client-1 with version 00.00.01 should connect to Server-1 And client 2 with version 00.00.02 should connect to Server-2 For load balancing I checked HAProxy lua support but couldn't find

Lua - attempt to call global 'contains' (a nil value)

雨燕双飞 提交于 2021-02-08 12:08:57
问题 I'm interesting, if who know what is the problem of this code bellow. I always get this error: ''attempt to call global 'contains' (a nil value)'' Here is the code: state1={10,11,20,21,22,23,24,30,31,32,33,34,35,36,37,38,39,40,45,46,47,48,49,50,51,69,72,73,74,85} state3={78} state4={1,2,3,4,5,6} playerskin=initArray2(32,0) wepskin=initArray2(32,0) function getPlayerData(id,d) if (d=="team") then if (player(id,"team")==1) then return "red" end if (player(id,"team")==2) then return "blu" end

Lua - attempt to call global 'contains' (a nil value)

六月ゝ 毕业季﹏ 提交于 2021-02-08 12:05:58
问题 I'm interesting, if who know what is the problem of this code bellow. I always get this error: ''attempt to call global 'contains' (a nil value)'' Here is the code: state1={10,11,20,21,22,23,24,30,31,32,33,34,35,36,37,38,39,40,45,46,47,48,49,50,51,69,72,73,74,85} state3={78} state4={1,2,3,4,5,6} playerskin=initArray2(32,0) wepskin=initArray2(32,0) function getPlayerData(id,d) if (d=="team") then if (player(id,"team")==1) then return "red" end if (player(id,"team")==2) then return "blu" end

Lua - attempt to call global 'contains' (a nil value)

北城以北 提交于 2021-02-08 12:05:41
问题 I'm interesting, if who know what is the problem of this code bellow. I always get this error: ''attempt to call global 'contains' (a nil value)'' Here is the code: state1={10,11,20,21,22,23,24,30,31,32,33,34,35,36,37,38,39,40,45,46,47,48,49,50,51,69,72,73,74,85} state3={78} state4={1,2,3,4,5,6} playerskin=initArray2(32,0) wepskin=initArray2(32,0) function getPlayerData(id,d) if (d=="team") then if (player(id,"team")==1) then return "red" end if (player(id,"team")==2) then return "blu" end

Do the Amazon SES documentation examples use a consistent, known set of example keys?

痞子三分冷 提交于 2021-02-08 09:51:15
问题 I am trying to write a Lua library for Amazon SES that will allow me to send API requests. I've poured over the documentation and various examples but I am continuing to get the following error: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. One of my functions somewhere along the line is formatting data incorrectly or doing something to cause the end result of

Install luaSQL on Ubuntu

可紊 提交于 2021-02-08 08:01:33
问题 TL;DR: You can skip to here. I was trying to use luarocks installer, but the apt-get installer did it without problems. I am experiencing issues when installing luaSQL on Ubuntu. I need it for a script that uses luasql = require "luasql.mysql" . I followed the official documentation which can be found here: http://keplerproject.github.io/luasql/doc/us/ What I've tried (and what was suggested by the official documentation): sudo luarocks install luasql-mysql gave me the following output: Error

How to print a table's contents within a table? [Lua]

大城市里の小女人 提交于 2021-02-08 07:18:24
问题 What I want to do is ONLY print a table's contents within a table. For example: local stats = { table1 = { tTable1 = { data = 1 }, tTable2 = { data2 = 2 }, tTable3 = { data3 = 3 }, } } I don't really care about table1 or all the tTables but rather the information in the data variables. How can I print them? This is a snippet of my real code: local stats = { [1] = { [1] = { [1] = 1, [2] = -1, [3] = -1, ["n"] = 3, }, [2] = { [1] = nuclearcraft:cooler, [2] = 10, ["n"] = 2, }, ["n"] = 2, }, [2] =

Lua function expects two parameters even when I have declared the function with one parameter

為{幸葍}努か 提交于 2021-02-08 05:27:16
问题 Consider the Lua code below: local util = {} function util:foo(p) print (p or "p is nil") end util.foo("Hello World") util.foo(nil, "Hello World") When I run this in lua console, I get following result: p is nil Hello World Can somebody explain this behavior to me. Edit I got the code working by making following change: local util = {} function util.foo(p) print (p or "p is nil") end util.foo("Hello World") util.foo(nil, "Hello World") I am fairly new to Lua, so any pointers/links explaining