如何将Terra Rawstring转换为LUA弦?
我有一些返回char *
的C代码,或者在Terra中RawString
。
如何将这种类型的值传递给LUA并将其用作普通字符串?
如果重要的话,将在堆上分配原肌(我不需要释放它)。
I have some C code that returns char *
, or rawstring
in Terra.
How can I pass a value of this type to Lua and use it as a normal string?
If it matters, the rawstring is allocated on the heap (and I won't need to free it).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 luajit的
ffi> ffi.string
- 字符串:
请注意,
ffi.string()
采用一个可选的长度参数,可以避免使用strlen
对其进行计算,并且该字符串已在LUA(可能会泄漏内存)。Use LuaJIT's
ffi.string
function:And to prove it works even with non-literal Strings:
Notice that
ffi.string()
takes an optional length parameter, which may be handy to avoid usingstrlen
to compute it, and that the string is interned in Lua (which may leak memory).