C&放大器; LUA:luaL_dostring返回值 [英] C & Lua: luaL_dostring return value

查看:2524
本文介绍了C&放大器; LUA:luaL_dostring返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的C文件我称之为luaL_dostring是这样的:

  luaL_dostring(L,回报somestring');

我怎么这行后读取C这个返回值?

感谢。

编辑:
感谢您的帮助。

我想补充一点,检索后要删除的元素,你可以使用:

 调用lua_pop(L,1);


解决方案

该值留在Lua的堆栈。为了检索的值,使用的 lua_toXXXX 的功能之一,为-1索引参数(-1指堆栈的顶部)。另外,使用 lua_gettop()来获取堆栈的大小。

在你的情况,使用:

  luaL_dostring(L,回报somestring');
为const char *海峡= lua_tostring(L,-1);

in my C file I call luaL_dostring like this:

luaL_dostring(L, "return 'somestring'");

How do I read this return value in C after this line?

Thanks.

Edit: Thanks for the help.

I'd like to add that to remove the element after retrieving it, you use:

lua_pop(L, 1);

解决方案

The value is left on the Lua stack. In order to retrieve the value, use one of the lua_toXXXX functions, with -1 as the index argument (-1 refers to the top of the stack). Alternatively, use lua_gettop() to get the size of the stack.

In your case, use this:

luaL_dostring(L, "return 'somestring'");
const char * str = lua_tostring(L, -1);

这篇关于C&放大器; LUA:luaL_dostring返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆