KeraLua icon indicating copy to clipboard operation
KeraLua copied to clipboard

Add methods to obtain pointers to Lua strings directly

Open pkhead opened this issue 8 months ago • 1 comments

It would be nice if there were methods to obtain direct pointers to Lua strings. These would be an alternative to CheckBuffer and ToBuffer, though I wouldn't mind if OptBuffer didn't get the same treatment. These methods would be unsafe and return a byte*, of course, or probably an IntPtr.

My use case is for passing Lua strings directly into a function loaded from a C library. Currently, I have to use CheckBuffer to obtain the unprocessed character data, then allocate a new byte buffer with an extra byte allocated for the null byte, and then pass it to the C function. This extra processing is a waste of time. Plus, the NativeMethods class is internal, so I couldn't sanely access the function I wanted.

If instead this issue was implemented, it would give me peace of mind.

pkhead avatar Jun 01 '25 12:06 pkhead

Can you send a PR ? Which methods? You can add new method like IntPtr ToRawString or IntPtr ToRawStringUnsafe

viniciusjarina avatar Jun 20 '25 06:06 viniciusjarina