Skip to content
Discussion options

You must be logged in to vote

LuaBridge decides by the C++ return type: T / const T are pushed as a copy (Lua lifetime), while T& / const T& / pointers are pushed as a reference to the C++ object (C++ lifetime, and read-only for const). See Passing Objects in the docs. So you need to register something that returns Vector3f by value. The simplest way is a lambda:

.beginClass<Entity>("Entity")
    // const& -> Lua gets a const reference to e.position
    .addFunction("getPosition", &Entity::getPosition)
    // by value -> Lua gets its own copy
    .addFunction("getPositionCopy", [](const Entity* e) { return e->getPosition(); })
    // works for properties too
    .addProperty("position", [](const Entity* e) { return e->g…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by 3lyrion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants