lua-5.2

How to store a value type in a userdata?

强颜欢笑 提交于 2019-12-04 18:41:39
This SO article is the same thing, but the answer is unhelpful because the answer was in Lua and the question was about the C-API. So I'm asking again. Hopefully, others will benefit from this question. I'm actually having 2 problems (I can't get y an z to work, and I can't get helloworld() to work) I'm trying to get to this: local x = MyCBoundLib.GetSomething() print(x.y) print(x.z) Where x is a userdata. I keep getting attempt to index a userdata value I know that " userdata isn't indexable without a metatable because it's C/C++ data " In my C-code, I do something like this to try and wrap

Recommended way to have 2+ modules recursively refer to each other in Lua 5.2

旧时模样 提交于 2019-12-03 07:40:59
Is there a way to have Two Lua modules (let's call them A and B ) Each module uses functions from the other, so they must require each other A third module (let's call it C ) can use A but not B e.g. C.lua : local A = require 'A' -- ... A.foo() There may be another module D that requires B but not A and/or E requiring both A and B Neither A nor B nor their members should be added to the global namespace. Avoid using the module and setfenv functions (deprecated in Lua 5.2) Related : Lua - how do I use one lib from another? (note: this solution does not handle circular dependencies.) I found

Loop through all Lua global variables in C++ [duplicate]

会有一股神秘感。 提交于 2019-11-30 21:06:12
This question already has an answer here: Iterating through a Lua table from C++? 3 answers I have been searching for quite a while now and I haven't found a way to fetch all the global variables from C++. Consider this small Lua test script. myGlobal1 = "Global 1" myGlobal2 = 2 function test() local l1=0 print (myGlobal1,myGlobal2,l1) end test() Assume you pause the execution at print (myGlobal1,myGlobal2,l1) and from C++ get all the global variables ( myGlobal1 and myGlobal2 ). These examples are arbitrary, the global variables, from a C++ point of view, are unknown. I have been looking at

luaL_openlib replacement for Lua 5.2

让人想犯罪 __ 提交于 2019-11-30 06:39:07
I am adapting a library written for Lua < 5.2 and got to a call I don't know the equivalent of: luaL_openlib(L, "Polycore", polycoreLib, 0); Where polycoreLib is a static const struct luaL_Reg polycoreLib [] How can I replace the call to luaL_openlib ? The lua wiki only states : Calls such as luaL_openlib(L, name, lreg, x); should be carefully rewritten because a global table with the given name will be searched and possibly created. There's two answers to this: one for replicating the behaviour of earlier versions here (where a global table is created), and one for implementing the behaviour

Loop through all Lua global variables in C++ [duplicate]

可紊 提交于 2019-11-30 05:44:48
问题 This question already has answers here : Iterating through a Lua table from C++? (3 answers) Closed 5 years ago . I have been searching for quite a while now and I haven't found a way to fetch all the global variables from C++. Consider this small Lua test script. myGlobal1 = "Global 1" myGlobal2 = 2 function test() local l1=0 print (myGlobal1,myGlobal2,l1) end test() Assume you pause the execution at print (myGlobal1,myGlobal2,l1) and from C++ get all the global variables ( myGlobal1 and

How to use Lua 5.2 with luasocket 3

一个人想着一个人 提交于 2019-11-29 06:46:12
I am trying to compile luasocket 3 that I found on GitHub with lua 5.2 . Problem is, I'm not sure how to bind together Lua with luasocket . Do I need to compile luasocket as DLL and then reference if somewhere in lua code, or should I just call it from lua console? Try installing it using luarocks . If you don't have luarocks, install it following instructions on the site. Then download the rockspec file(luasocket-scm-0.rockspec) from luasocket repo and run $ luarocks install *path to the rockspec file* If everything goes OK, you'll be able to use luasocket from Lua like this: local socket =

luaL_openlib replacement for Lua 5.2

 ̄綄美尐妖づ 提交于 2019-11-29 05:45:12
问题 I am adapting a library written for Lua < 5.2 and got to a call I don't know the equivalent of: luaL_openlib(L, "Polycore", polycoreLib, 0); Where polycoreLib is a static const struct luaL_Reg polycoreLib [] How can I replace the call to luaL_openlib ? The lua wiki only states: Calls such as luaL_openlib(L, name, lreg, x); should be carefully rewritten because a global table with the given name will be searched and possibly created. 回答1: There's two answers to this: one for replicating the

How to use Lua 5.2 with luasocket 3

﹥>﹥吖頭↗ 提交于 2019-11-28 00:29:40
问题 I am trying to compile luasocket 3 that I found on GitHub with lua 5.2. Problem is, I'm not sure how to bind together Lua with luasocket . Do I need to compile luasocket as DLL and then reference if somewhere in lua code, or should I just call it from lua console? 回答1: Try installing it using luarocks. If you don't have luarocks, install it following instructions on the site. Then download the rockspec file(luasocket-scm-0.rockspec) from luasocket repo and run $ luarocks install *path to the