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

Create/access nested tables in lua via C/C++

how to create nested tables? My approach sadly does not work. I thought that lua_newtable pushes a new table on the stack and if I do lua_settable that should set key value pair, but I was mistaken apparently. /* * local transform =…
ezyn
  • 11
  • 3
1
vote
1 answer

luaL_loadbufferx returns syntaxerrors

I'm working on a personal project and I'm trying to get Lua to work on my embedded device. I have my own simple file system that works with the the flash drive, and now I'm trying to use modules for the lua scripts that I run on the device. I have…
Viktor Krum
  • 33
  • 1
  • 10
1
vote
2 answers

C++ Lua access violation when table size is above treshold

Recently I became Lua expert in my team due to an issue occurring when we want to send a large table to the following function: int native_sl_shootlaserpulse(lua_State* L) { int iRetVal = 0; // L1 is class instance luaL_checktype(L,…
1
vote
0 answers

Why does calling lua_newuserdata result in SIGSEGV Segmentation Fault?

I'm trying to identify why a call to lua_newuserdata result in SIGSEGV. The gdb backtrace is : Thread 2 "main.o" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff7c1a700 (LWP 41635)] 0x0000555555573bbe in sweepstep.constprop…
humand
  • 11
  • 3
1
vote
1 answer

lua_tostring adding a hyphen to the end of a string?

This function: static int function_name(lua_State *L) { const char* str = lua_tostring(L, 1); const char* substr = lua_tostring(L, 2); // passing "how" results in "how-" ??? char *pch = strstr(str, substr); if (pch != NULL) …
wellinthatcase
  • 120
  • 2
  • 8
1
vote
1 answer

Create nested tables from C

I'm trying to create this datastructure from C: local table = { id = 12, items = { { id = 1, name = "foo", },{ id = 2, name = "bar", } } } However I don't manage to…
iveqy
  • 19,951
  • 1
  • 15
  • 20
1
vote
1 answer

How to create a multi-dimensional Lua table with Lua C Api...?

Hi I want lua C api to create Lua table like table={['key1']={5,4,3,2},['key2']={1,0,1,1,0},['key3']={0,10,0,30,0,50}} thanks in-advance....
Abhi
  • 73
  • 8
1
vote
0 answers

Lua 5.4, having trouble requiring a Lua module DLL (Windows)

I want to experience with the Lua internals a little bit and affiliate myself with them. I figured digging into the C API would give me some neat knowledge. I wrote up a very small module (parser.dll) in pure C: #include "parser.h" #pragma…
wellinthatcase
  • 120
  • 2
  • 8
1
vote
1 answer

How can I read and write to nested lua tables from C++?

I have a nested table in my lua code that I want to pass to C++ so the native code can manipulate it: -- Some persistent data in my game local data = { { 44, 34, 0, 7, }, { 4, 4, 1, 3, }, } -- Pass it into a C++ function that can…
idbrii
  • 10,975
  • 5
  • 66
  • 107
1
vote
0 answers

How to handle with return number given by lua_resume?

I have some coroutine handling code like this: int coro_re_num = 0; int coro_state = lua_resume( coro_lua, master_lua, narg, &coro_re_num); if ( coro_state == LUA_OK) { // do something } else if ( coro_state == LUA_YIELD) { //…
jiandingzhe
  • 1,881
  • 15
  • 35
1
vote
0 answers

Lua crashed when calling a script function from a C++ function called from script

In brief, I called Lua script function aaa, aaa called C++ function testfunc, and when testfunc going to call script function bbb, it crashed. This is the Lua-side code: foo = 100 function aaa() testfunc(foo * 2) end function bbb(...) for…
jiandingzhe
  • 1,881
  • 15
  • 35
1
vote
1 answer

Is it harmless to luaL_unref twice?

When referencing a value like so: lua_pushnumber(L, 1); ref = luaL_ref(L, LUA_REGISTRYINDEX); Is it harmless to unreference ref multiple times or will this cause problems? i.e. is it harmless to call luaL_unref(L, LUA_REGISTRYINDEX, ref) multiple…
Andreas
  • 9,245
  • 9
  • 49
  • 97
1
vote
0 answers

Access Lua coroutine from C

I have implemented a co-routine system. When I press ENTER to clear the first textbox, it calls contscript() which in turn calls lua_resume() but it doesn't continue the co-routine. So what do I pass to lua_resume() to make the co-routine…
1
vote
1 answer

How to find how many items(values) are in lua stack

I'm working with lua in C++ and I want to find how many "slots"(you can say) are being used in lua stack, and if possible, what is the size of lua stack?
ahmed
  • 88
  • 1
  • 9
1
vote
1 answer

Can you check what I understood about lua stack is right?

I'm learning lua. I don't understand why this is wrong. This is my lua code -- lua Enemy = { HP = 30, SPEED = 8, POWER = 10 } And this is my cpp code. It will access to Enemy table and each value. ... lua_getglobal(L, "Enemy"); /* …
woohyeon
  • 29
  • 6