隐式声明 luaL_openlibs。
2011-12-5 13:54:52
收藏:0
阅读:131
评论:2
我正在编写一个将Lua嵌入到C程序中的简单测试。
我在Windows/Mingw和Linux上都遇到了同样的问题。 这是Linux上我使用的gcc命令:
gcc -Wall -o test_lua lua_test.c -I/usr/include/lua5.1 -llua5.1
在Windows上:
gcc -Wall -o test_lua.exe lua_test.c -llua5.1
在两种情况下,我都会得到以下警告:
warning: implicit declaration of function
'luaL_openlibs' [-Wimplicit-function-declaration]
程序可以正常工作,但我可能没有在其中使用任何标准的Lua库?
为什么我会收到这个警告?我在lauxlib.h
中看到了luaL_openLibs
的定义!
这是C部分:
#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int status;
lua_State *L;
L = luaL_newstate();
// Init lua
luaL_openlibs(L);
// Load script
status = luaL_loadfile(L,"lua_test.lua");
if (status) {
fprintf(stderr,"Couldn't load file\n");
exit(1);
}
// Push data
lua_pushnumber(L, 5000);
lua_setglobal(L, "clife");
lua_pushnumber(L, 6000);
lua_setglobal(L, "ttime");
lua_pushnumber(L, 3000);
lua_setglobal(L, "atime");
// Run script
int result = lua_pcall(L, 0, LUA_MULTRET, 0);
if (result) {
fprintf(stderr,"Failed to run script: %s\n", lua_tostring(L,-1));
exit(1);
}
// Value at top of the stack is the result
const char *schedule = lua_tostring(L,-1);
fprintf(stdout,"Computed schedule is: %s\n", schedule);
// Close lua
lua_pop(L, 1);
lua_close(L);
return 0;
}
这是Lua部分:
io.write("lua_test.lua -- will generate schedule\n")
io.write("Wizard life is " .. clife .. "\n")
schedule = ""
ctime = ttime - atime
if clife > 4500 then
schedule = schedule .. "[" .. ctime .. ",p]"
schedule = schedule .. "[" .. ctime+500 .. ",a]"
schedule = schedule .. "[" .. ctime+1000 .. ",i]"
schedule = schedule .. "[" .. ctime+1500 .. ",n]\n"
else
schedule = schedule .. "[" .. ctime .. ",d]"
schedule = schedule .. "[" .. ctime+500 .. ",r]"
schedule = schedule .. "[" .. ctime+1000 .. ",a]"
schedule = schedule .. "[" .. ctime+1500 .. ",i]"
schedule = schedule .. "[" .. ctime+1500 .. ",n]\n"
end
io.write("Returning " .. schedule .. "\n");
return schedule
原文链接 https://stackoverflow.com/questions/8386352
点赞
stackoverflow用户1593299
May be luaL_openlibs defines in a ifdef block.
Use `-E` with gcc to get the source after preprocessing. Pipe. Grep.
可能在 ifdef
块中定义了 luaL_openlibs
。
使用 gcc
的 -E
选项以获取预处理后的源代码。使用管道和 grep
命令。
2012-08-12 10:32:48
评论区的留言会收到邮件通知哦~
推荐文章
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
- 如何编写 Lua 模式将字符串(嵌套数组)转换为真正的数组?
据我所知,在我的 5.1.4 版本安装中,该函数位于 lualib.h,而不是 lauxlib.h。