Comments (12)
How about adding a method to luabridge::Result that throws if there is an error. So the pattern could be:
luabridge::push(L, value).throw_on_error();
Sound like a great idea, will look into a proposal
from luabridge3.
- Juse use
addFunction
it detects it automatically. - Yes, you have to handle the return value and not discard it. That's whats the
[[nodiscard]]
means.
from luabridge3.
Thanks for replying. I know what nodiscard
means. I'm just not sure what I'm supposed to do with the return value. Can you give an example of the correct code?
from luabridge3.
FWIW: For the moment, I silenced the warning thusly:
luabridge::Stack<CMPER>::push(l, returnVal.first) LB3(.operator bool());
LB3
is a macro that strips out the code if it is compiling with OG LuaBridge.
The [[nodiscard]]
seems like an overly fussy requirement. The only situation it can fail is with the stack checking enabled. At the very least, it should be conditional on whether LUABRIDGE_SAFE_STACK_CHECKS
is enabled.
from luabridge3.
pushing on the stack can fail for multiple reasons and it's always safer to handle the case, you'll save yourself from additional grey hairs.
from luabridge3.
Regarding non intrusive shared refcounting, luabridge RefCountedPtr
is suboptimal design with architectural flaws (for example having an unprotected global static map of pointers is way unsafe and inefficient). If you still want to go that route, it's easy to roll your own, but it is not a solution the library should suggest as a preferred way to handle the case.
from luabridge3.
stack pushing
I would be interested in seeing the coding pattern for stack pushing that for you is optimal. If it involves an ugly sequence of if statements, I will push back with the observation that this is why we have luaL_error
. :-)
non-intrusive lifetime sharing
Surely you agree that the library is of much more limited value if there is no way to have shared lifetime on a class without modifying it. (It would present a formidable barrier to using the library for my project, for example.) That said, I am not particularly in love with RefCountedPtr
as implemented. Indeed, a couple of years ago I uncovered some flaws in it myself, which have subsequently been addressed.
I am just brainstorming, but I'm wondering if it would be possible to re-implement RefCountedPtr
as a wrapper around std::shared_ptr
. Would that not get around the issues with type erasure? Just based on how RefCountedPtr
works now, it seems like it might.
using LuaBridge in a Clib
One of the big problems with the current implementation of RefCountedPtr
is that a Clib compiled with LuaBridge can't use it safely. That's because the Clib has its own version of the static global map. I don't know if any shared pointer scheme works in this situation, though.
But this problem extends more fundamentally into LuaBridge. A Clib cannot safely register classes, either, at least not on LB2. They work just fine, but then the program crashes when the Lua state closes. I'm guessing there must be a hidden global somewhere, but I haven't ever bothered to go looking for it.
from luabridge3.
Safety is the principle i'm adhering the library on, by relying on lua_error
we are forcing the library to assume we have exceptions on (the lua panic handler cannot return or it aborts the application). I don't work like that and prefer to have the library to allow you to chose. You don't care ? write a lightweight wrapper and be fine with it. You want exception thrown or lua_error called from C++ ? write a ligthweight wrapper to throw your exceptions / lua errors in c++ land. But please don't force me to work this way (i can't, our game engine can't run with exceptions on for several reasons i won't explain in detail).
// You dont' care ? then simply don't care
template <class T>
void push(lua_State* L, T&& value)
{
(void) luabridge::push(L, value);
}
// You care but you need exceptions ? throw
template <class T>
void push(lua_State* L, T&& value)
{
if (auto result = luabridge::push(L, value); not result)
throw std::runtime_error(result.message());
}
// I can't use neither of the two. I care about safety but couldn't run with exceptions.
Moreover Stack::push
is a C++ api not a lua one so it needs to behave safely from a C++ context. I don't normally push a lot of object by hand but let luabridge do the push for me when i call binded methods / functions, so i don't care if i need to handle the errors explicitly. Error handling is nice and safe and it's way better than receiving some exception somewhere else in the code, that might or might not handle correctly the error in the first place (too generic, and you don't know how to handle it, too specific and you'll have try catch blocks as granular as checking the result value of push).
from luabridge3.
I'm using Stack::push
when I need my C function to return multiple values. If there is a bound way to do this, I would be happy to switch.
How about adding a method to luabridge::Result
that throws if there is an error. So the pattern could be:
luabridge::push(L, value).throw_on_error();
Or something like that.
from luabridge3.
RefCountedPtr
is broken. It's not scalable with thousands of objects (we have nearly hundred thousands), and doing lookups all the time is hitting badly a resonably big sized game, moreover those accesses are not thread safe which is a problem for us (and making it thread safe just increase contention which is slowing down the whole game). And yes, luabridge3 is safe to use across dll boundaries, and RefCountedPtr
was preventing that safety from a library standpoint as well.
from luabridge3.
Are comments about RefCountedPtr
in relation to the draft PR #85 I just posted? Or about the old one?
from luabridge3.
Old one is broken, new one is incomplete as you cannot recover the reference count back safely into C++ land from lua.
from luabridge3.
Related Issues (20)
- Enhancement Request: Custom error function for `lua_pcall`. HOT 11
- Error C3861 (using with Luau) HOT 3
- Can I cast types inside Lua? HOT 4
- Duplicate symbols on Win32 with default __stdcall HOT 9
- Debug names of C functions for Luau HOT 8
- Extensible class bug with inheritance
- Add support for addStaticIndexMetamethod and addStaticNewIndexMetamethod
- Using LuaBridge3 in a precompiled header on MSVC leads to an internal compiler error HOT 2
- Use of std::shared_ptr on classes without `std::enable_shared_from_this` HOT 1
- Stateful lambdas registered as functions loose state HOT 2
- Compile error with Cfunc property getter/setter HOT 2
- std::vector to 0-based Lua table HOT 5
- MSC Warning C4146 HOT 2
- How to expose C++ data (a vector, in this case) to Lua without making a copy? HOT 2
- Does LuaBridge3 Support Android for SDL2-based Games? HOT 2
- Passing a Lua Table (LuaRef) as an argument to C++ function HOT 1
- How to get the name of a Lua variable? HOT 2
- Comparison Issue Between `uint64_t` in C++ and Numeric Constant in Lua HOT 8
- NAI run lua code in string from cpp
- Explicit inclusion of `#include <stdint.h>`. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from luabridge3.