Questions tagged [luabridge]

LuaBridge is a lightweight, dependency-free library for mapping data, functions, and classes between C++ and Lua.

LuaBridge is a lightweight C++ library that has no external dependencies. Its purpose is to make it easy to expose C++ functions and classes to Lua. LuaBridge has been tested and works with Lua revisions starting from 5.1.5, although it should work in any version of Lua from 5.1.0 as well as LuaJit.

64 questions
2
votes
1 answer

Accessing Tables In Lua From C++

I have a global table in Lua I am trying to access from C++. Here is essentially what I am trying to do: Lua: myTable = {} myTable[1] = 1 C++: lua_State* L = luaL_newstate(); luaL_openlibs(L); lua_pcall(L, 0, 0, 0); lua_State* L2 =…
OT2O
  • 129
  • 2
  • 3
  • 8
2
votes
2 answers

Cannot get a Lua function to reference 'self'

I'm trying to create a simple class with a member function that would print out some member values, but I'm getting errors when I try to reference 'self': attempt to index global 'self' (a nil value) Here's the script I'm trying to run: Test =…
manabreak
  • 5,415
  • 7
  • 39
  • 96
2
votes
1 answer

Easiest way to pass an enumerated type from Lua to C++?

I am trying to load textures from a Lua script, to my game engine in C++. The engine uses a class called "ResourceHolder" and the enumerated type is from a class called "ResourceIdenifiers". My game scene creates its own ResourceHolder for both…
user50286
  • 125
  • 2
  • 6
2
votes
1 answer

Not able to modify objects passed to lua

Considering the following example of using LuaBridge to pass objects to a lua script: class Test { public: double d; Test(double t): d(t) {}; }; Test t1(10); auto lua_state =…
Appleshell
  • 7,088
  • 6
  • 47
  • 96
2
votes
2 answers

LuaBridge doesnt create the constructor right

I use LuaBridge to port some classes and functions to Lua. I'm currently debugging and I always get main.lua:1: attempt to call method 'new' (a nil value) this is main.lua : v = TexVector:new( 1, 2 ) v.X = 0 v.Y = 0 print( v.X, v.Y ) -- print and…
Joshua Behrens
  • 818
  • 13
  • 23
1
vote
0 answers

Lua crashes when doing operations of userdata metatables in C

I've stumbled upon a problem in Lua. I am using a library to bind C++ classes to Lua but the problem seems to be in Lua and not related to the library. Steps to reproduce the crash: Expose a C++ class to Lua as userdata and bind a function to a…
SuperUser
  • 331
  • 2
  • 6
  • 21
1
vote
1 answer

Iterating C array-type container class from Lua using LuaBridge

This may be a newbie question, but I have not been able to find an answer with web searching that will even help me get started. I have a container class that at heart is a C-style array. For simplicity, let's depict it as this: int *myArray = new…
rpatters1
  • 382
  • 1
  • 11
1
vote
1 answer

How to pass lua table to the c++ class Constructor using luaBridge?

This is what i want to make. int lua: object1 = MyObjectClass({1,2,3}); in c++ class MyObjectClass { public: MyObjectClass(/*How to passed lua table here?*/) { } void printmynum() { } }; getGlobalNamespace(L) …
medq
  • 21
  • 2
1
vote
1 answer

C++ Call Lua Functions

I'm just about to include Lua in my project. Only have one problem, if I link my own class and create it in Lua, the stack is not cleaned up and I get memory leaks. The Memory Go Up and Up. MyClass: class CTest { public: CTest(std::string s) …
darealcore
  • 11
  • 1
1
vote
0 answers

Changing the _ENV of a lua_thread (using C API)

This is for a multiplayer game where NPC scripts will be loaded and cached as function chunks on a single lua_State, and then each time a player interacts with an NPC, a new lua_thread is created, a cached function is fetched from a global lua_table…
newbane2
  • 130
  • 5
1
vote
0 answers

Error working with Lua modules using LuaBridge and C++

I am unable to include a Lua file in another Lua file. I am compiling Lua using C++ and LuaBridge. Here is my main function. Very very small. lua_State* luaState = luaL_newstate(); luaL_openlibs(luaState); luaL_dofile(luaState,…
1
vote
0 answers

Luabridge not working without "luaL_openlibs(L)"

I cannot use luabridge without having the following line: luaL_openlibs(lState); And I don't even use its library functions. I get this error : Assertion failed: lua_istable (L, -1) Just my adding "luaL_openlibs(lState)", no problems occur, but…
1
vote
0 answers

Exposing correct factory classes to lua

So I am writing a factory system to create objects and using lua to call them. however I am struggling to figure out how to expose them to lua using luaBridge. I have a template factory: template { T* create(Id…
yik
  • 65
  • 5
1
vote
1 answer

Calling C++ class function from LUA script

I'm attempting to learn how to use lua/luabridge to call member function of a class, but I'm having some trouble: Here is the simple test class: class proxy { public: void doSomething(char* str) { std::cout << "doDomething called!: "…
Ian Young
  • 1,712
  • 1
  • 16
  • 33
1
vote
1 answer

luabridge bind C++ member, but not change member value

I have a question by using luabridge, it change C++ value fail, for exam: //c++ files struct Coor3D_1 { int lon; }; class ETALink{ public: ETALink() { } Coor3D_1 coor3D_1; }; bind code is…
zhengzheng
  • 11
  • 2