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

Strange lua push/pop behavior with the C API

I noticed that pushing and popping values onto/off the stack in lua using the C API on my target platform (32-bit PowerPC architecture) behaves very oddly. Consider the following test function: void test_pushing_and_popping(lua_State *lua) { …
BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
3
votes
2 answers

Lua C API: Handling and storing additional arguments

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…
Jan
  • 31
  • 1
  • 2
3
votes
1 answer

access nested tables from Lua to C to get values

Hi I am trying to access a nested table sent from Lua to C. The table is: arg = { MagicNumber = {MagicNumber, 0}, ProdNum = {ProdNum, 1}, LetterR = {LetterR, 0xc}, Revision = {Revision, 0xd}, Space1 = …
SanR
  • 43
  • 5
3
votes
2 answers

What is the difference between Lua registry with light userdata and references?

So with the Lua C API you can save a Lua value in the registry and retrieve it later. There are different ways to do it, you can create a variable and use it's pointer as the key in the registry as it's always unique. You would push the pointer as…
Resantic
  • 57
  • 1
  • 7
3
votes
2 answers

tolua++: Transfer pointer ownership to lua gc

Is there a way to return objects allocated on the the heap to lua without 'caching' references to them? Consider the following: class foo { char const* bar() const { char* s = malloc(...); ... return s; // << Leak.…
user3647854
3
votes
2 answers

Lua C API How to determine were function called as class member or just function from table?

I have C++ application which uses Lua C API. I declared global table via lua api: lua_newtable(L); lua_pushstring(L, "someLuaFunc"); lua_pushcfunction(L, &someCFunc); lua_settable(L, -3); lua_setglobal(L, "table1"); and now I can call someLuaFunc…
user1204080
3
votes
1 answer

How to use macro in lua

Was looking now few threads on lua and found this post very interesting: Alert messages for lua functions I am trying to use the same macro to my code with some changes to operation: #define GET_INTEGER_WARN(ind, fld) do { \ lua_getfield(L, ind,…
Marcos Silva
  • 53
  • 1
  • 6
3
votes
2 answers

How to return a list of values from Lua to C and print them one by one?

I am using C API embedded with Lua. My goal is that: pass an array of integers into Lua and calculate their factorials, then the results are passed back to C and printed out. To realize the goal, my C code is: #include #include…
gladys0313
  • 2,569
  • 6
  • 27
  • 51
3
votes
2 answers

Lua registered C function calling another one

Say I have two C functions registered in my Lua scope: int func1(lua_State* L) { int n = lua_gettop(L); // Do sth here... } int func2(lua_State* L) { int n = lua_gettop(L); // Do sth here... } The question is: can I call func2…
babel92
  • 767
  • 1
  • 11
  • 21
3
votes
1 answer

How do I create a Lua module inside a Lua module in C?

I have an Actor that I want to give a Script. Instead of having multiple shared-objects, I would like to have a single, top-level module that includes its own dependencies. In other words, I want to be able to do this: Actor = require…
Leroy
  • 237
  • 2
  • 12
3
votes
1 answer

Lua C++ userdata matrix access to elements

I have a matrix class in C++ and the constructor is as follows: template CMatrix::CMatrix(unsigned int varrow,unsigned int varcolumn) { //Lets set member variables this->m_row=varrow;this->m_column=varcolumn; …
macroland
  • 973
  • 9
  • 27
3
votes
2 answers

Equality operator on mixed types in Lua

In chapter 13.2 of Programming in Lua it's stated that Unlike arithmetic metamethods, relational metamethods do not support mixed types. and at the same time Lua calls the equality metamethod only when the two objects being compared share this…
whoever
  • 575
  • 4
  • 18
3
votes
1 answer

Get table as auto argument when calling C function from the same table field

I have several global integer variables, like A0, A1, A2 in Lua script. They are declared on C side. Each of them contains unique numeric value. In a script user manipulates device pins using this aliases: set_pin_bool(A0, 1) And this calls…
pugnator
  • 665
  • 10
  • 27
3
votes
2 answers

How to associate a lua_sethook context with lua_sethook?

I'm trying to write a debugger for a process running lua scripts, and the documented way of doing so (in C) is to use lua_sethook: int lua_sethook (lua_State *L, lua_Hook f, int mask, int count); lua_Hook is defined as: typedef void (*lua_Hook)…
Tom
  • 653
  • 1
  • 8
  • 15
3
votes
1 answer

C++ and Lua integration with arguments (...) (Lua 5.1)

I'm currently trying to pass a function from C++ to Lua. Problem is that this function has a parameter of (int, int, char *, ...). I'm pretty new at using Lua as well. So I got all the arguments from the lua stack, and I put the relevant (...) ones…
user2418426
  • 105
  • 1
  • 12
1 2
3
13 14