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
0 answers

Should loaded libraries be left on stack?

I am preparing my state and loading libraries like so: luaL_requiref(L, "libname", luaopen_libname, 1); After that, when I look at the stack, I can see that every library leaves a value on it (the stack). Should it be like that or should I pop the…
Sherlock Holmes
  • 191
  • 1
  • 8
1
vote
1 answer

Can I pass a value from my C host through Lua to a callback C function?

I have Lua embedded in a C host. And I have several C functions registered with Lua. Is there any way that when I call Lua and then Lua calls my C function, a value can be passed along from the "outer" C code to the "inner" C code? The specific…
Anthony Mills
  • 8,676
  • 4
  • 32
  • 51
1
vote
1 answer

how to create multidimensionnal array in lua with lau C api

I have an inquiry about the binding between lua and c languages. lua usage example) a[1].b.c[1].d = 1 a[1].b.c[2].d = 2 a[2].b.c[1].d = 3 a[2].b.c[2].d = 4 I am wondering how to create this with lua C api. This is the code I used in C …
P.Kwon
  • 21
  • 2
1
vote
0 answers

Unwanted metatable change

I think I have messed up my stack somewhere. Here's ultimately what's happening. local tg = require "tgeasy" local drawBuffer = tg.start(); tg.stop(); print(drawBuffer.pointer, getmetatable(drawBuffer.pointer).__name); local charInfo =…
AlgoRythm
  • 1,196
  • 10
  • 31
1
vote
2 answers

Lua C API - Assign and use object member of a class from C++

I'm trying to instantiate and use object of Lua classes from C++. Lua class is defined like this. myclass = {} function myclass:new(o) o=o or {} setmetatable(o,self) self.__index=self return o end function myclass:init() …
Philiste
  • 161
  • 13
1
vote
0 answers

C Lua Bindings Windows VS2017

I would like to build a .dll filled with Lua bindings written in C compiled using VS 2017, but I don't seem to be having any luck, and the resources available to me are confusing and, by majority, outdated. Here is what I've done. I've already…
AlgoRythm
  • 1,196
  • 10
  • 31
1
vote
2 answers

Lua - Why are C functions returned as userdata?

I'm working on game scripting for my engine and am using a metatable to redirect functions from a table (which stores custom functions and data for players) to a userdata object (which is the main implementation for my Player class) so that users…
tayoung
  • 411
  • 1
  • 4
  • 16
1
vote
1 answer

Lua c API - Add number to new lib

(Lua 5.2) I am writing bindings from ncurses to Lua and I want to include some values other than functions. I am currently binding functions like this: #define VERSION "0.1.0" // Method implementation static int example(lua_State* L){ return…
AlgoRythm
  • 158
  • 10
1
vote
1 answer

What is the difference between lua_getmetatable and luaL_getmetatable

Lua API has a function lua_getmetatable which will fetch the table with metafunctions if the value has one. Lua auxiliary library (which is part of lua API) has another function luaL_getmetatable which is a macro that will fetch a value from…
Teivaz
  • 5,462
  • 4
  • 37
  • 75
1
vote
1 answer

How to call a library function by its name and setting it's parameters

I have a library functions defined like that in my C code : static const struct luaL_reg SelSurfaceLib [] = { {"CapabilityConst", CapabilityConst}, {"create", createsurface}, {NULL, NULL} }; static const struct luaL_reg SelSurfaceM [] =…
1
vote
1 answer

lua - store closure in C, invoke async in C

I need an idea, how I can store lua closures to invoke them asynchronously later. my first idea was lua_tocfunction but a closure is not a cfunction and cannot be invoked from C directly second idea was to save the closure in the metatable, that I…
Aitch
  • 1,617
  • 13
  • 24
1
vote
2 answers

duktape closure registration

I have C++ project and I'm using duktape JS library. I need to register global function in JS and save pointer to object as closure data with this function, so I can access this pointer when function is called. I know how to do this in lua c…
user1204080
1
vote
0 answers

with creating table in table in Lua C-API

I use this code for creating table in table (Like namespace) in Lua C-API: JNIEXPORT void JNICALL Java_com_naef_jnlua_LuaState_lua_1import_1tables(JNIEnv *env, jobject obj, jstring namespace) { lua_State *L; JNLUA_ENV(env); L =…
BORSHEVIK
  • 794
  • 1
  • 8
  • 12
1
vote
0 answers

Segfault when lua_newtable called 100 times in a row

When I'm trying to add 100 tables in Lua c stack, I receive segfault on function end. Code example: lua_example.c: http://pastebin.com/GFvLwMY2 Makefile: http://pastebin.com/3EWJiVz7 test.lua: http://pastebin.com/1y22XvzK Maybe I'm doing it wrong?…
marsgpl
  • 552
  • 2
  • 12
1
vote
3 answers

Calling lua functions from .lua's using handles?

I'm working on a small project trying to integrate lua with c++. My problem however is as follows: I have multiple lua scripts, lets call them s1.lua s2.lua and s3.lua. Each of these has the following functions: setVars() and executeResults(). Now I…
Karrok
  • 115
  • 1
  • 4
  • 13