Closed Python1320 closed 10 years ago
Can you write me your use case of this piece of code?
You can use strings with lua::String
or const char*
like this:
state.set("text", "hello");
std::string str = lua::String(state["text"]);
When you push allocated pointer of std::string
then you must release this new allocated pointer...
I needed to push data that was not null terminated and could contain zeroes, for which I needed lua_pushlstring. This implementation might not be the cleanest, but it did the job and I don't believe I'm leaking memory using it like this: https://github.com/Python1320/feidi/commit/e9f7e2f2974a250289bc22fc896f4239e25728c1#diff-7ec3c68a81efff79b6ca22ac1f1eabbaR140
I added conversion functions. So when you want to set std::string
use setString
function... When you want to set pointer std::string*
, use setPtr<std::string*>
function.
Later when you want to retrieve std::string
, you can use toString
function
This allows pushing binary data using lua_pushlstring