lua

Invoke Rest api end point in LUA

£可爱£侵袭症+ 提交于 2021-01-27 22:16:05
问题 I need to invoke a Rest API endpoint from my Lua script. How can I do that? For example, I am able to invoke the endpoint by the below curl command: curl -X GET \ -H "X-Parse-Application-Id: ParseAppID" \ -H "X-Parse-REST-API-Key: RESTAPIKey" \ https://api.parse.com/1/classes/GameScore The same I wanted in Lua. 回答1: You have lots of options LuaSocket Lua-HTTP Lua-cURL (probably more) All of them are slightly different, but all of them can call your API endpoint. 回答2: Lua by itself cannot call

Full path to the required value

拜拜、爱过 提交于 2021-01-27 20:11:26
问题 How do I get the full path to the required value in the table? I want to track changes in another table through a proxy table. I understand that I need to use metatables and __index in it. But I haven't been able to come up with a tracker yet. Sample table structure: Objects = { Panel = { layer = 1, x = 600, y = 328, w = 331, h = 491; objects = { label = { layer = 1, x = 0, y = 0, text = 'header' }; Window = { layer = 2, x = 400, y = 100, w = 100, h = 100; objects = { label = { layer = 1, x =

Can you modify a C struct from lua?

亡梦爱人 提交于 2021-01-27 19:16:19
问题 I want to be able to have this Lua code: function myfunc(s) print(s.value) s.value = 7 end And it should work with this C(++) code: struct MyStruct { float value; }; void func() { MyStruct var; var.value = 5; lua_getglobal(L, "myfunc"); // push `var` to lua, somehow lua_call(L, 1, 0); // prints "5" // now, var.value is 7 assert(var.value == 7); } How would I push var onto the stack such that the lua code can modify its variables? 回答1: Standard Lua doesn't have a built-in way to expose the

LuaSocket socket/core.dll required location?

柔情痞子 提交于 2021-01-27 18:16:49
问题 When I use local socket = require("socket.core") It works fine, the dll is located at "dir/socket/core.dll" but when I move the dll to say "dir/folder/core.dll" and use local socket = require("folder.core.") It returns that it was found however it could not find the specific module in folder.core. How do I use Luasocket outside of it's socket.core requirements? Thanks! 回答1: If you want to require("socket.core") , the shared library (dll) has to have an exported function called luaopen_socket

Iterate through XML nodes with Lua

核能气质少年 提交于 2021-01-27 14:20:21
问题 I'm trying to iterate through all the 'FindMe' nodes but I'm struggling with the pattern matching. This is going to be used as a plugin in another piece of software so I'm trying to avoid using a parsing library. Given the following xml <?xml version="1.0" encoding="utf-8"?> <NodeA> <NodeB> <FindMe attr="1"> <NodeC attr="1" /> </FindMe> <FindMe attr="2"> <NodeC attr="2" /> </FindMe> </NodeB> </NodeA> When I try this it only prints the last match for k, _ in src:gmatch(".+(<FindMe .+</FindMe>)

counting string-indexed tables in lua

我与影子孤独终老i 提交于 2021-01-27 14:08:04
问题 I am trying to count elements in a table that has some elements indexed with strings. When I try to use the # operator, it just ignores string indexed ones. example: local myTab = {1,2,3} print(#myTab) will return 3 local myTab = {} myTab["hello"] = 100 print(#myTab) will return 0 mixing them, I tried local myTab = {1,2,3,nil,5,nil,7} print(#myTab) myTab["test"] = try print(#myTab) returned 7 and then 3, that is right because I read somewhere that the # operator stops when it finds a nil

HAproxy+Lua: Return requests if validation fails from Lua script

孤街醉人 提交于 2021-01-27 08:33:16
问题 We are trying to build an incoming request validation platform using HAProxy+Lua. Our use-case is to create a LUA scripts that will essentially make a socket call to a Validation API, and based on the response from Validation API we want to redirect the request to a backend API, and if the validation fails we would want to return the request right from the LUA script. For example, for 200 response we would want to redirect the request to backend api, and for 404 we would want to return the

After table.getn got deprected in Logitech 5.4 LUA this code doesn't seems to work anymore

自闭症网瘾萝莉.ら 提交于 2021-01-27 07:08:38
问题 After Logitech API got updated for the 5.4 Lua version, table.getn got deprected and some guys that helped me said I could update the code with # but the logic of the code doesn't seems to work anymore with this replacement, I have tried making some workaround the code but I'm not very familiar with programming, how could I fix this code for Logitech API? Could someone guide me? Sense = 1.4; --Rate of FIRE (in seconds) G36ROF = 10 --600RPM. HKROF = 11.1 --666RPM. ROF = {G36ROF, HK417ROF} -

Lua: attempt to compare boolean with number

孤人 提交于 2021-01-27 05:23:50
问题 I came across an error: attempt to compare boolean with number with the following code: local x = get_x_from_db() -- x maybe -2, -1 or integer like 12345 if 0 < x < 128 then -- do something end What causes this error? Thanks. 回答1: 0 < x < 128 is equivalent to (0 < x) < 128) , hence the error message. Write the test as 0 < x and x < 128 . 回答2: writing 0 < x < 128 is okay in Python, but not in Lua. So, when your code is executed, Lua will first calculate if 0 < x is true . If it is true, then

Lua: attempt to compare boolean with number

99封情书 提交于 2021-01-27 05:21:11
问题 I came across an error: attempt to compare boolean with number with the following code: local x = get_x_from_db() -- x maybe -2, -1 or integer like 12345 if 0 < x < 128 then -- do something end What causes this error? Thanks. 回答1: 0 < x < 128 is equivalent to (0 < x) < 128) , hence the error message. Write the test as 0 < x and x < 128 . 回答2: writing 0 < x < 128 is okay in Python, but not in Lua. So, when your code is executed, Lua will first calculate if 0 < x is true . If it is true, then