lua-5.2

UPDATE cell value if a pair matches

时光毁灭记忆、已成空白 提交于 2020-01-06 02:33:10
问题 I am using luasql. I have two tables of this type: IPINFO CREATE TABLE `ipstats` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `ip` VARCHAR(15) NOT NULL, `last_used` DATETIME NOT NULL DEFAULT '1981-09-30 00:00:00', PRIMARY KEY (`id`), UNIQUE INDEX `ip` (`ip`) ) COLLATE='utf8_general_ci' ENGINE=MyISAM ROW_FORMAT=DEFAULT and another table ipnstats: CREATE TABLE `ipnstats` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `ipstats_id` INT(10) UNSIGNED NOT NULL, `nick` VARCHAR(32) NOT NULL,

Lua 5.2 issue: 'attempt to call a nil value' from lua_pcall

丶灬走出姿态 提交于 2020-01-02 03:17:34
问题 I'm having problems getting a Lua 5.2 function to get called from C++. This is the Lua chunk (named test.lua): function testFunction () print "Hello World" end And this is the C++: int iErr = 0; //Create a lua state lua_State *lua = luaL_newstate(); // Load io library luaopen_io (lua); //load the chunk we want to execute (test.lua) iErr = luaL_loadfile(lua, "test.lua"); if (iErr == 0) { printf("successfully loaded test.lua\n"); // Push the function name onto the stack lua_getglobal(lua,

How to filter out user defined globals in Lua from C++?

送分小仙女□ 提交于 2019-12-22 23:22:03
问题 Consider this small Lua test script. g1 = "Global 1" g2 = "Global 2" function test () local l1 print(g1,g2,l1) end test() Assume you pause the execution at print(g1,g2,l1) and from C++ get all the global variables with this C code: lua_pushglobaltable(L); lua_pushnil(L); while (lua_next(L,-2) != 0) { const char* name = lua_tostring(L,-2); // How do I tell a user defined // global variable (now in name) // from all other environment variables? lua_pop(L,1); } lua_pop(L,1); // global table When

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

你说的曾经没有我的故事 提交于 2019-12-21 01:21:40
问题 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

Create new C library in lua

不想你离开。 提交于 2019-12-20 03:56:08
问题 I want to know how i can create and use a new C library in lua 5.2.3. I can't use dynamic library (require, shared library, ...) due to I am on an embedded system. I found an answer but it is for lua 5.0 (http://www.lua.org/pil/26.2.html) and so it is not compatible. If someone have a idea ? 回答1: Edit linit.c and add your library entry point to it. Then add the modified linit.c to your project. The linker will use your copy instead of the one in the Lua library. This assumes your app calls

How to store a value type in a userdata?

我们两清 提交于 2019-12-09 23:24:00
问题 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

Porting to Lua 5.2, LUA_GLOBALSINDEX trouble

大城市里の小女人 提交于 2019-12-08 20:01:14
问题 In the code example: http://lua-users.org/wiki/SimplerCppBinding There is the code: lua_pushstring(L, T::className); lua_pushvalue(L, methods); lua_settable(L, LUA_GLOBALSINDEX); //<--- LUA_GLOBALSINDEX removed in Lua 5.2 lua_pushliteral(L, "__metatable"); lua_pushvalue(L, methods); lua_settable(L, metatable); In Lua 5.2, LUA_GLOBALSINDEX no longer exists. Instead, it has lua_setglobal() and lua_getglobal(). Am I correct in thinking that: lua_pushvalue(L, methods); lua_setglobal(L, T:

what is actual implementation of lua __pairs?

心不动则不痛 提交于 2019-12-07 02:30:38
问题 Does anybody know actual implementation of lua 5.2. metamethod __pairs ? In other words, how do I implement __pairs as a metamethod in a metatable so that it works exactly same with pairs() ? I need to override __pairs and want to skip some dummy variables that I add in a table. 回答1: The following would use the metatable meta to explicitly provide pairs default behavior: function meta.__pairs(t) return next, t, nil end Now, for skipping specific elements, we must replace the returned next :

Lua 5.2 issue: 'attempt to call a nil value' from lua_pcall

孤人 提交于 2019-12-05 07:53:48
I'm having problems getting a Lua 5.2 function to get called from C++. This is the Lua chunk (named test.lua): function testFunction () print "Hello World" end And this is the C++: int iErr = 0; //Create a lua state lua_State *lua = luaL_newstate(); // Load io library luaopen_io (lua); //load the chunk we want to execute (test.lua) iErr = luaL_loadfile(lua, "test.lua"); if (iErr == 0) { printf("successfully loaded test.lua\n"); // Push the function name onto the stack lua_getglobal(lua, "testFunction"); printf("called lua_getglobal. lua stack height is now %d\n", lua_gettop(lua)); //Call our

what is actual implementation of lua __pairs?

岁酱吖の 提交于 2019-12-05 06:06:49
Does anybody know actual implementation of lua 5.2. metamethod __pairs ? In other words, how do I implement __pairs as a metamethod in a metatable so that it works exactly same with pairs() ? I need to override __pairs and want to skip some dummy variables that I add in a table. The following would use the metatable meta to explicitly provide pairs default behavior: function meta.__pairs(t) return next, t, nil end Now, for skipping specific elements, we must replace the returned next : function meta.__pairs(t) return function(t, k) local v repeat k, v = next(t, k) until k == nil or theseok(t,