Questions tagged [lua-api]

Anything related to Lua C Application Programming Interface (Lua C-API).

Lua has been designed to be easily integrated with C applications, thus it provides a rich API to interact with C code, which is called the Lua C-API.

The Lua C-API can be used both for:

  • enabling the Lua engine to communicate with an host application (the application which embeds the engine), and

  • enabling library code for Lua written in C to communicate with the Lua engine that loads the library.

197 questions
1
vote
1 answer

Bind c++ static functions from another class to Lua

Hy! My problem is simple: I have a function in the extendedgamefunctions class: In the header: #include "Gameitems.h" extern "C" { #include "lua.h" #include "lualib.h" #include "lauxlib.h" }; extern std::vector>…
Bady
  • 56
  • 8
1
vote
0 answers

How to inject a method into an object with Lua's C api

I've got a userdata object I've created. I've defined the object like this: static const luaL_Reg object_methods[] = { {"__gc", pbject_gc}, {"__tostring", object_print}, { NULL, NULL } }; static int object_new (lua_State *L) { …
Leroy
  • 237
  • 2
  • 12
1
vote
0 answers

Close shared library when closing lua state

I'm using a custom shared library from lua. To load this library I have the required by Lua function luaopen_mylib. However this library needs to free resources and other thing when its being unloaded; so I'm wondering, does Lua calls some function…
Javier Mr
  • 2,130
  • 4
  • 31
  • 39
1
vote
0 answers

How to read a table in lua

I have a table as follows below. Table = { 1, 2, 3, 6, 7, 8, 11, 12, 13,... } I want to read that table and say how many values were read, the more I'm having trouble with my code below, always…
carolzinha
  • 101
  • 1
  • 7
1
vote
1 answer

Lua table of string values as parameter in C function

I want to make a C function that takes a lua table with strings as parameter, and the lua table does not have any keys, just values. How can I do this? I cannot figure it out. I did not find anything when I searched in google.
Erik W
  • 2,590
  • 4
  • 20
  • 33
1
vote
1 answer

Handling Lua calls and errors in C in a bulletproof way

I work on Lua electronic device simulation plug in. I want to make it good in design and usability, as most probably a lot of users are far from IT and debugging. Users describe device in Lua and plug in translates it via Lua C API. Users may…
pugnator
  • 665
  • 10
  • 27
1
vote
1 answer

use lua's lightuserdata to register timer callback

I would like to wrap the C timer (not alarm) and use it within lua, in a way that I could specify a callback function to be triggered after one second have passed. In order to use multiple timer, a timer ID and callback will be stored to a…
uudiin
  • 23
  • 2
1
vote
1 answer

Lua: Read table parameter from c function call

I'm really unsure about handling tables in the C API of Lua. The interface I'm currently developing requires me to read contents of a table given to my c function: example.lua: myVector2 = {["x"]=20, ["y"]=30} setSomePosition(myVector2) C…
InDieTasten
  • 2,092
  • 1
  • 16
  • 24
1
vote
2 answers

C: replace table from call

Can I replace a table? e.g. I cannot get this working: lua_createtable(L,0,0); lua_replace(L,2); // is the 2nd parameter of a function call
WWebber
  • 91
  • 8
1
vote
1 answer

Pass upvalue to Lua 5.2 module in C

I am trying to create an experimentation environment for myself where my application runs as a telnet server for theoretically unlimited telnet clients that can execute Lua commands in their own Lua environment. For this, every client has its own…
scippie
  • 2,011
  • 1
  • 26
  • 42
1
vote
0 answers

luaL_ref takes a error on table?

Now, I have two modules, CModule and CModule2. In CModule, My code like below: static int RegisterTable(lua_State *L) { luaL_checktype(L, 1, LUA_TTABLE); int iRef = luaL_ref(L, LUA_REGISTRYINDEX); lua_pushinteger(L, iRef); return…
vipygd
  • 78
  • 7
1
vote
1 answer

Error when creating lua table from inside the c api

I have an A* algorithm in C, intended to be used from Lua. Now, the A* itself works fine but for some weird reason, when I call it from Lua, there's a weird error that pops out when any one of the argument functions (Neighbours) creates a table.…
kuniqs
  • 308
  • 1
  • 9
1
vote
0 answers

call lua state from every c++ file

I added lua into my c++ project and now I would like to know if its somehow possible to set the "L" global or something like that? lua_State* L = lua_open(); currently I have in the main function: lua_State* L = lua_open(); luaopen_base(L); but on…
metabeta
  • 27
  • 2
1
vote
1 answer

Passing nested tables from Lua to C

I have the following nested table defined in Lua. I need to pass it into my C++ program so that I can accurately read it's values. I know I can pass a single table to Lua using the lua_getglobal(L, "parameters") function. But in this case…
shaveenk
  • 1,983
  • 7
  • 25
  • 37
1
vote
2 answers

Nested Lua Metatables in C

In a 3D scene, I have an Object that has a position that I would like to move using Lua. eg. box.position.x = 10 box has a metatable ("Object") and so has position ("Vec"). Object has __newindex and __index set to call C functions NewIndexObject…