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
12
votes
3 answers

Is there a good way to expose sf::Event to Lua with Luabridge?

According to the LuaBridge readme, LuaBridge does not support "Enumerated constants", which I assume is just enums. Since sf::Event is almost entirely enums, is there any way I can expose the class? Currently the only other solution I can come up…
Ben Hollier
  • 585
  • 2
  • 11
  • 32
7
votes
1 answer

Luabridge weak reference to LuaRef data

Consider the following example: function Process() local Container=NewContainer() Container:On(EventType.Add,function() Container:DoSomething() end) -- Does not Garbage Collect end In luabridge, I store the function() as…
Grapes
  • 2,473
  • 3
  • 26
  • 42
6
votes
2 answers

Modifying a C++ array in main() from Lua without extra allocation

I am sketching a small C++ program that will pass arrays to Lua and have them modified there, where I intend to have a lua script read in the program so I can modify it without needing to recompile the program My first obstacle is to ensure Lua is…
JayY
  • 109
  • 10
4
votes
1 answer

LuaBridge and Member Functions

I just downloaded LuaBridge today and am very satisfied with it so far. One thing I've noticed is that I'm able to circumvent the normal requirement of having a lua_State as a function parameter. I can do this: //C++ files void love(int i)…
M89
  • 71
  • 1
  • 6
3
votes
0 answers

How to overload arithmetic operators with luabridge using c++ global operator?

I'm trying to implement a Vector3 class in Lua using Luabridge. So far I am able to construct it, and access each component like you'd expect (x, y, z). An example in Lua would look like this: local v = Vec3(0, 0, 0) Now, I'd like to overload the…
Belfer4
  • 351
  • 3
  • 11
3
votes
0 answers

Return of 2 identical userdata

I want new and at to return the same userdata, please tell me how to do it example code that I use struct SCheckpoint { rage::ICheckpoint* r_Checkpoint; SCheckpoint(rage::ICheckpoint* checkpoint) { r_Checkpoint = checkpoint; …
kemperrr
  • 31
  • 1
  • 3
3
votes
1 answer

How to register a templated function with LuaBridge?

I'm new to Lua and LuaBridge and I'm trying to figure out if it's possible to register a templated function? I've looked online and through the LuaBridge manual to no avail. What I tried was creating a pointer to the base class, but then found out…
Harish Bhagat
  • 31
  • 1
  • 4
3
votes
1 answer

How to convert Lua userdata to C++ class object?

I have this Lua code: function returnPerson() local person = Person("Mike", 23) return person end It returns userdata representing Person(C++ class registered using LuaBridge). So I call this function using lua_pcall and now the last…
Stefan Dimeski
  • 438
  • 4
  • 16
3
votes
0 answers

C2664 "Cannot convert from const to &" when trying to expose classes to Lua

I'm trying to expose two classes to Lua using LuaBridge. These classes are Sprite and Texture that look something like this: class Texture { public: Texture(const std::string& filename); ... } class Sprite { public: Sprite(Texture&…
manabreak
  • 5,415
  • 7
  • 39
  • 96
3
votes
1 answer

Implementing C++ -to-lua observer pattern?

I have an observer (or "listener") pattern implemented in my code as such: struct EntityListener { public: virtual void entityModified(Entity& e) = 0; }; class Entity { public: Entity(); void setListener(EntityListener*…
manabreak
  • 5,415
  • 7
  • 39
  • 96
2
votes
0 answers

Why sol2 is slower than LuaBridge3?

I've done some benchmarks (lua-benchmarks). For some reason sol2 perform slower than LuaBridge3. In sol2 repo you can find benchmarks showing that sol2 have to outperform LuaBridge3 (benchmarks), but for some reason on real use cases it's not. In…
Alterise
  • 21
  • 2
2
votes
1 answer

Binding LuaJIT to C++ with LuaBridge results in "PANIC: unprotected error"

Windows 10 x64, MSVC 2017, LuaJIT 2.0.5. I searched the web, but answers didn't help. Basically I'm trying to follow this manual, except that I had to place #include after Lua includes, because otherwise it doesn't work saying that the…
user64675
  • 482
  • 7
  • 25
2
votes
1 answer

Luabridge binding overloaded operators

I've written a simple vec3 class, which implements the */+- operators: class vec3 { public: vec3(): x(0.0f),y(0.0f),z(0.0f) {} vec3(float ix, float iy, float iz): x(ix),y(iy),z(iz) {} vec3 operator+(const vec3& v){ …
Ian Young
  • 1,712
  • 1
  • 16
  • 33
2
votes
1 answer

variable arguments in lambda as function pointer

I want to copy a function from one Lua_State to another using luabridge. luabridge provides a Function called addFunction(const char * name,FP fp) and an Function called getGlobal(lua_State* L,const char*) which returns a Object of Type LuaRef which…
Raphl10
  • 56
  • 2
  • 6
2
votes
1 answer

How to use .addFunction for class methods which returns std:vectors using Luabridge

I have a class like this in Visual Studio C++ 2012 (with C++ v.11): #pragma once #include struct Object { public: std::string _name; double _number; std::vector _list; public: Object(); Object(std::string,…
makiwhtie
  • 51
  • 6
1
2 3 4 5