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

Select nested value with selector string with the Lua C API

Assumed I have a value defined in nested tables: tab["m"]["b"] = {}. In Lua, I can just define it with the previous statement. Is that possible with the C API too? Specifically instead of pushing tab, m, etc. individually, selecting the value with a…
Appleshell
  • 7,088
  • 6
  • 47
  • 96
1
vote
1 answer

How call function in lua library with dlsym

I am trying call a lua library runtime, so I made a lua lib in C static int my_new(lua_State *L) { printf("test_new"); } LUALIB_API int luaopen_my(lua_State *L) { static const luaL_Reg R[] = { { "new", my_new }, {…
Alex
  • 3,301
  • 4
  • 29
  • 43
1
vote
2 answers

Why the c++ object destructor not called when luaL_error is called?

I have a piece of code like this class Test { public: Test() {printf(">>> Test()\n");} ~Test() {printf(">>> ~Test()\n");} } int myFunc(lua_State *L) { Test t; luaL_error(L, "error"); return 0; } I know when lua complied by c…
Kery
  • 513
  • 8
  • 22
1
vote
1 answer

Amend values of a Lua table using c-api

A table in lua is defined as below tab = {"Sunday", 14.5, "Tuesday", "Wednesday", 63, -92, "Saturday", "Saturday", 111} Lua call a c function, and the tab table is set as a param, this c function should return the table after it has been…
Messady
  • 45
  • 2
  • 7
1
vote
1 answer

Lua C API: inserting table elements cause Debug Assertion Failed

Function returns successfully and I can use values from the table but the error "Debug Assertion Failed" shows up and it's the end. I know that the problem with assert is in the for loop but don't exactly know how to fix that. Thanks in…
deepspace
  • 771
  • 3
  • 11
  • 25
1
vote
1 answer

How to "%q" format a lua_Buffer in the C-API

string.format("%q", foo_str) will format a string to add the appropriate escape chars to make it safe to read back into the Lua interpreter. How can I best use this function to format a Lua_Buffer from the C-API? More generally, how can I access…
Paul
  • 2,973
  • 6
  • 31
  • 40
0
votes
0 answers

Why is my C++ object becoming nulled when I pass a lua value containing it to a lua script/function ue4, lua machine

I've exposed some C++ functions to Lua so that I can retrieve/manipulate data from objects of class UTableBase(Not user data). But whenever I pass FLuaValues containing a non user data object to a function or script it seems like the object pointer…
0
votes
1 answer

Lua (g hub api) mouse not moving

I have a problem with Lua mouse script using G hub api. Everything works except for mouse-move functions, for example MoveMouseTo or MoveMouseRelative. Even MoveMouseWheel works fine. Here is my code. Thank you for any feedback. There are no error…
German
  • 1
  • 1
0
votes
0 answers

Modsecurity Custom Lua Rule Not Capturing REQUEST_HEADERS

I'm using Modsecurity 3.0.9 with Nginx version: nginx/1.23.4 I created custom rule which executes Lua (Lua5.3) script as the following: SecRuleScript "/path/to/lua/script.lua" "id:1,phase:3,deny" /path/to/lua/script.lua content: local headers =…
Udi Aharon
  • 13
  • 3
0
votes
1 answer

Unprotected error when calling nested Lua C library function with lua_pcall()

I'm writing a C++ library function that takes in two tables and takes the values from the tables and puts them into a vector. To reduce clutter I've also made a helper function that will read the values in one of the tables and performs some type…
cooljacwty
  • 13
  • 5
0
votes
0 answers

Calling next multiple times in loop causes stack overflow in ue4 Lua machine

I've been working on lua machine json object system. But I've hit a snag with the json object merger(You can see the functions code used below). When I try to iterate through a table using a while loop and IterateTable function, and then ether call…
0
votes
1 answer

How to properly register a C++ class in lua for multiple calls

Can't correctly register the C++ constructor in lua. Using the lua C API I made such a wrapper of the class: namespace API { struct Vector2 { double x = 0; double y = 0; Vector2(const LuaStack& args); }; …
b0ryakha
  • 13
  • 3
0
votes
0 answers

Accessing the Lua stack from different threads (Lua C api)

Suppose i have one lua stack: lua_State* L From the first thread, I only add elements to the lua stack and remove elements from the top of the stack. From the second thread, I read from the Lua stack - ONLY guaranteed to exist items on the…
Lua_beg
  • 31
  • 6
0
votes
0 answers

lua_getglobal triggered "attempt to index a thread value" error

I have completely no idea on how it could raise this error: even if the global does not exist, isn't it should give a nil? Nevertheless, something I could ensure are: it is a valid lua_State; it is the main context, not a thread; the named global…
jiandingzhe
  • 1,881
  • 15
  • 35
0
votes
1 answer

How to change key press when clicking the same button twice using G-series Lua API v8.45

As the title says im looking to find out how to make it so that when i click one of the buttons on my mouse (mouse 4-6) that it will press a key but if i double click that same button it presses a different key.