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

How to add a message of amount of settings

well I have a question, I was wondering if it is possible to count the settings that exist within a function lua_getglobal. I have a file called define.lua he is as follows: tbl { macro_enable = true; macro_value = 100; time_expire =…
carolzinha
  • 101
  • 1
  • 7
0
votes
1 answer

How to apply lua a definition

I have a definition as follows: #define namef (s, r, x) (p_name ((s), (r), (x))) My file lua is follows: tbl= { name_func = module; }; my code is as follows: void getname(void) { lua_State *L = luaL_newstate(); luaL_openlibs(L); …
Chozie
  • 73
  • 1
  • 9
0
votes
1 answer

Lua pass table to function, modify it and get it back in C++

I'm trying to add functionality in my program where I pass a C++ struct into Lua function let it play with it and then set it back to C++ program. Lua function: function test( arg ) arg.var1 = arg.var1 * 2 arg.var2 = 1 end C++…
kokodude
  • 13
  • 2
0
votes
1 answer

addEventListner not working in Lua

Here's the relevant functions in my code, I get the following error: Stack traceback: [C]: in function 'error' ?: in function 'getOrCreateTable' ?: in function 'addEventListener' ?: in function 'addEventListener' main.lua:26: in function…
0
votes
0 answers

Adding lua source to project giving linker error

I've added the lua source to my DLL project (removed lua.c and luac.c). I have the below code as a DLL project in VS and I'm getting a lua_createtable() linker error (lua_newtable() is a macro that calls lua_createtable()). What's odd is…
user441521
  • 6,942
  • 23
  • 88
  • 160
0
votes
0 answers

Compile linker file for embedding C code in Lua 5.2.1

How can I compile the file for the linker in visual studio 2010. These are the steps I follow with Lua 5.2.1 source code with Visual Studio 2010: cl /MD /O2 /c /DLUA_BUILD_AS_DLL *.c Rename "lua.obj" and "luac.obj" with the extention ".o" Sso they…
Azoun
  • 255
  • 3
  • 14
0
votes
0 answers

C++/Lua function sometimes writes data to a file

I have a function in c++ to write data to file: static int SaveFile(lua_State *L) { string file = lua_tostring(L,1); string data = lua_tostring(L,2); while(true) { string::size_type position = data.find ("\\"); if (position ==…
Arko
  • 3
  • 2
0
votes
0 answers

Is is better to use multiple states or environments in Lua?

I've got a scripted program, and I'm currently using multiple states for different environments, to ensure user and system scripts don't mess with each other. What are the pros/cons of using multiple environments against a single context instead?
Phil Lello
  • 8,377
  • 2
  • 25
  • 34
0
votes
1 answer

Call Lua function from C++ using LuaBridge

I am having some trouble calling Lua functions from C++ using LuaBridge. The idea is that I want to call "Update" on the script on every game update in C++. The following code is what I have found online: LuaRef sumNumbers = getGlobal(L,…
Serguei Fedorov
  • 7,763
  • 9
  • 63
  • 94
0
votes
0 answers

C lua function crash

I have made a C module for lua as a dll that I load in Lua using the package.loadlib function. The module is supposed to use luaL_loadstring to execute some lua code from a string. My lua script is run by an application I didn't code myself, and my…
Dennefyren
  • 344
  • 1
  • 2
  • 8
0
votes
2 answers

How to iterate over a table modified with luaL_ref and luaL_unref?

I'm using Lua's C API to extend Lua. In my module, I want to populate a table using luaL_ref, and remove fields using luaL_unref. I also want to be able to iterate over this table, hopefully using lua_next. Iterating over the table is a problem…
tprk77
  • 1,151
  • 1
  • 9
  • 22
0
votes
1 answer

Compiling Love 2D Xcode : Undefined Symbols for Architecture

How do i get these "symbols" recognized by the compiler when i compile c++ in xcode. here's the errors ( i have a feeling that its ignoring the frameworks then giving errors for missing frameworks) ld: warning: ignoring file…
JqueryToAddNumbers
  • 1,063
  • 3
  • 14
  • 28
0
votes
2 answers

Lua create multiple closure instances

I have some lua code in a file. I want to create multiple closure instances of this code, each with a different _ENV upvalue. I can use luaL_loadfile to load the file and set the first upvalue, N times with different tables, to create N instances.…
z33m
  • 5,993
  • 1
  • 31
  • 42
-1
votes
1 answer

Alert messages for lua functions

I have the following code: lua_getglobal(L, "lgd"); lua_getfield(L, -1, "value_pos_x"); cr->value_pos_x = lua_tointeger(L, -1); if (!lua_isinteger(L, -1)) printf("value_pos_x allows only numbers;"); lua_getfield(L, -2,…
Chozie
  • 73
  • 1
  • 9
-1
votes
1 answer

Panic error while reading file lua

I created a file with the following code Request = { TimeAdd = true; DaysAdd = true; }; The source code is made in C lua_getglobal(L, "Request") lua_getfield(L, -1, "TimeAdd"); time_request = lua_toboolean(L, -1); …
Chozie
  • 73
  • 1
  • 9
1 2 3
13
14