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
2
votes
1 answer

Test if Lua number is integer or float

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…
glampert
  • 4,371
  • 2
  • 23
  • 49
2
votes
1 answer

Lua API push userdata

I'm trying to give a scripting ability to my component system. Of couse each component has a field "parent" which holds access to the parent Actor. I can write the code so I can access my C++ methods from Lua, but I got stuck when I want to return…
RobeeZ
  • 95
  • 9
2
votes
2 answers

How can I get list of all table names in .lua script using Lua C API?

I have a lua file which looks like this: tableA = {…} tableB = {…} tableC = {…} I want to get std::vector which will contain the names of all tables defined in file: {"tableA", "tableB", "tableC"} How can I do this with Lua C API?
user999040
2
votes
1 answer

Pointer to number

It seems like there's know such thing as a reference to a number/boolean/lightuserdata in Lua. However, what would be the easiest way to set a global in Lua that points to a C++ native type (e.g. float) and have it update automatically when I change…
TravisG
  • 2,373
  • 2
  • 30
  • 47
2
votes
1 answer

Lua Registry in required modules

Are keys set in the registry of a temporary state that's accessed in a module int luaopen_foo(lua_State*) adopted in the registry of the calling state? For example, let's say we have this module: int luaopen_foo(lua_State* state) { …
Appleshell
  • 7,088
  • 6
  • 47
  • 96
2
votes
1 answer

Getting a “pointer” to a Lua function stored in C

In the Lua C API I can store a number or a string from the stack with lua_tostring(). How can a “reference” (if that is the correct term) to a Lua function be passed to C through the Lua API? So it can be called later from C, with lua_call(),…
user1598585
2
votes
2 answers

Error loading module undefined symbol: luaL_setfuncs

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…
jordi
  • 1,157
  • 1
  • 13
  • 37
2
votes
1 answer

Details about function arguments through Lua C API

if I call a function foo(t[1]) through the C API, can I in any way see what table and what index is as argument, in this case t and 1? The problem at hand is a function move_card(card, table_slots[0]) where I move a card from one slot on a game area…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
2
votes
1 answer

Lua C API - mapping a property to a function

Is it possible to push a function as a property in Lua? Right now, I can have Get/Set functions by pushing them as fields like so: lua_pushcfunction(L,L_Getter); lua_setfield(L, -2, "GetValue"); lua_pushcfunction(L,L_Setter); lua_setfield(L,…
Grapes
  • 2,473
  • 3
  • 26
  • 42
2
votes
1 answer

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

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…
jorgander
  • 540
  • 1
  • 4
  • 12
2
votes
1 answer

Moving a lua table in C api

I'm attempting to move a table to another table using the lua C api. For instance, I have a table with this structure: a[b][c][d][e] = value I want to move table d this to be under a[b], which I could accomplish in Lua like: a[b][d] =…
Chrismit
  • 1,488
  • 14
  • 23
2
votes
1 answer

Can I initialize and work with two Lua buffers at the same time?

Given that the LuaL_Buffer object: "During its normal operation, a string buffer uses a variable number of stack slots", I don't understand how two luaL_Buffer objects can be used at the same time. Will they each assume the state of the stack is as…
Paul
  • 2,973
  • 6
  • 31
  • 40
1
vote
0 answers

Port lua (5.2-5.4) C++ connection to lua 5.1?

I'm working on the mGBA project (https://github.com/mgba-emu/mgba) and I'm trying to fix some problems regarding the scripting API and Lua 5.1. The project has the following functions: Load the Lua script: bool _luaLoad(struct mScriptEngineContext*…
Nuive
  • 11
  • 3
1
vote
0 answers

How to manage vector of pointers in C++ where pointer is allocated by Lua

In the simple 2D Game Engine I am working. I want to define and script my entities using Lua and do all the heavy work in C++ (rendering, physics, etc.) To do this I have basic Entity class: class Entity { public: Entity() { …
kaktusas2598
  • 641
  • 1
  • 7
  • 28
1
vote
0 answers

How to get number of entries from a lua_getglobal and name of entries in c code

I would like to know if there is any way for me to get the number of entries in a lua_getglobal and get the name of each entry I need to know why I need to use a loop to apply lua definitions in my C code: example moon code: Mytbl = { var = { …