我有一个Lua脚本,它调用一个C函数。目前,此函数不返回任何内容。我想要更改这个函数以返回一个字符串,所以在这个函数的末尾,我将把这个字符串推到Stack中。在调用Lua脚本中,我需要返回被推送的字符串值。C初始化和Lua注册{ Task task;
// Create a new Lua statethe function to be calle
如何安全地从Lua堆栈读取字符串值?函数lua_tostring和lua_tolstring都会引发Lua错误(longjmp _ of /奇怪类型的异常)。因此,这些函数可能应该在保护模式下使用lua_pcall调用。但我无法找到一个很好的解决方案,如何做到这一点,并获得字符串值从Lua栈到C++。是否真的需要使用lua_pcall在保护模式下调用lua_tolstring
实际上使用lua</e
有没有一种方法可以将堆上分配的对象返回给lua,而不对它们进行“缓存”引用?How to transfer the ownership of 's' to lua?};
如果将字符串返回给已分配的内存,则必须将其删除。有没有办法把所有权转让给lua?或者是否可以让lua_state*实现使用lua_pushstring(...)返回的字符串?
我的Lua表如下所示: bid_number=20; bid=table of 20 elements;static int forLua_SumArray (lua_State* L) { // Get the length of the table (same as # operatorin Lua) double sum = 0.0;