lua-api

Error loading module undefined symbol: luaL_setfuncs

南楼画角 提交于 2019-12-10 11:18:43
问题 I am trying to create a C module to be called from a lua script. I am working on debian linux. I am using mysql-proxy and lua 5.2. I have created (copied from a tutorial) some example functions to be called. The loader is defined like this: int luaopen_luacall(lua_State* l) { luaL_newlibtable(l, luacall); luaL_setfuncs(l, luacall, 0); return 1; } To call this from lua I use this code: luacall = require("luacall") local f = luacall.fun1() I have compiled it with this command: g++ -shared -Wl,

Test if Lua number is integer or float

梦想的初衷 提交于 2019-12-08 02:59:27
In my C++ program, I need to know if a Lua variable is an integer number or a floating-point number. The C API provides lua_isnumber() but this function does not distinguish between int/float/double . So far I have worked around this by using modf() : if (lua_isnumber(luaCtx, -1)) // int / unsigned int / float: { luaVarName = lua_tostring(luaCtx, -2); double n = static_cast<double>(lua_tonumber(luaCtx, -1)); // Figure out if int or float: double fractPart, intPart; fractPart = modf(n, &intPart); if (fractPart != 0.0) { luaVarType = ScriptVar::TypeTag::Float; luaVarData.asFloat = static_cast

lua_open returns null using luaJIT

折月煮酒 提交于 2019-12-07 01:52:35
问题 Using the recent luaJIT lua_open returns null . This does not happen with the regular lua library. lua_State *L = lua_open(); std::cout << L << std::endl; Output: 0x0 How can I get luaJIT to work? SSCCE: #include <iostream> #include <luajit-2.0/lua.hpp> //linked library: libluajit-5.1.a int main(int argc, const char * argv[]) { lua_State *L = luaL_newstate(); // lua_open(); std::cout << L << std::endl; // 0x0 } Additional information: Built on OSX 10.9 from source (tried both 2.0.2 and from

Error loading module undefined symbol: luaL_setfuncs

非 Y 不嫁゛ 提交于 2019-12-06 14:09:38
I am trying to create a C module to be called from a lua script. I am working on debian linux. I am using mysql-proxy and lua 5.2. I have created (copied from a tutorial) some example functions to be called. The loader is defined like this: int luaopen_luacall(lua_State* l) { luaL_newlibtable(l, luacall); luaL_setfuncs(l, luacall, 0); return 1; } To call this from lua I use this code: luacall = require("luacall") local f = luacall.fun1() I have compiled it with this command: g++ -shared -Wl,-E,-soname,libluacall.so -o luacall.so luacall.c -fPIC -llua -ldl When I try to run the script I get the

How do I set, via the lua C API, the environment table for a chunk of lua code prior to running it?

会有一股神秘感。 提交于 2019-12-06 10:49:18
问题 The interface for my game engine is built using a markup language and Lua, similar to HTML and javascript. As such, visual elements will have handlers for UI events such as a mouse move or click, and each time a handler is to be run, the engine will check if it is compiled yet and if not will compile it via luaL_loadstring . Handers can be shared either by element duplication or assignment ( this.onclick = that.onclick ). How do I set the environment of a chunk of lua code before running it?

Lua C API: Handling and storing additional arguments

为君一笑 提交于 2019-12-06 06:43:43
问题 CreateEntity is a C function I bound to Lua in my project. It takes an entity class name string as first argument, and any number of additional arguments which should get passed to the constructor of the chosen entity. For example, if CreateEntity was a normal Lua function I could do it this way: function CreateEntity( class, ... ) -- (choose a constructor function based on class) args = {...} -- (store args somewhere for whatever reason) TheConstructor( ... ) end But how can I do this with a

Weak table and GC finalizer using C API

大憨熊 提交于 2019-12-06 01:16:36
问题 I am attempting to create a GC finalizer for a function value by storing it in a weak table using the C API. I started off by writing a prototype in pure Lua 5.2: local function myfinalizer() print 'Called finalizer' end function myfunc() print 'Called myfunc' end local sentinels = setmetatable({}, { __mode='k' }) sentinels[myfunc] = setmetatable({}, { __gc=myfinalizer }) myfunc() myfunc = nil collectgarbage 'collect' print 'Closing Lua' Resulting output: Called myfunc Called finalizer

lua c read nested tables

那年仲夏 提交于 2019-12-05 09:47:01
below is the lua table i need to read from C: listen = { { port = 1234, address = "192.168.1.1", userdata = "liunx" }, { port = 1235, address = "192.168.1.2", userdata = "liunx1" }, { port = 1236, address = "192.168.1.3", userdata = "liunx2" } } below is the c code: #include <lua.h> /* Always include this when calling Lua */ #include <lauxlib.h> /* Always include this when calling Lua */ #include <lualib.h> /* Prototype for luaL_openlibs(), */ /* always include this when calling Lua */ #include <stdlib.h> /* For function exit() */ #include <stdio.h> /* For input/output */ void bail(lua_State

lua_open returns null using luaJIT

风格不统一 提交于 2019-12-05 08:22:41
Using the recent luaJIT lua_open returns null . This does not happen with the regular lua library. lua_State *L = lua_open(); std::cout << L << std::endl; Output: 0x0 How can I get luaJIT to work? SSCCE: #include <iostream> #include <luajit-2.0/lua.hpp> //linked library: libluajit-5.1.a int main(int argc, const char * argv[]) { lua_State *L = luaL_newstate(); // lua_open(); std::cout << L << std::endl; // 0x0 } Additional information: Built on OSX 10.9 from source (tried both 2.0.2 and from git) with make and make install . Using compiler: $ cc --version Apple LLVM version 5.0 (clang-500.2.79)

How do I set, via the lua C API, the environment table for a chunk of lua code prior to running it?

混江龙づ霸主 提交于 2019-12-04 16:17:48
The interface for my game engine is built using a markup language and Lua, similar to HTML and javascript. As such, visual elements will have handlers for UI events such as a mouse move or click, and each time a handler is to be run, the engine will check if it is compiled yet and if not will compile it via luaL_loadstring . Handers can be shared either by element duplication or assignment ( this.onclick = that.onclick ). How do I set the environment of a chunk of lua code before running it? The idea is to make element- and event-specific data available to the chunk, and also to link to the