加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

luaL_openlibs的隐式声明

发布时间:2020-12-16 05:30:32 所属栏目:百科 来源:网络整理
导读:我正在编写一个将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 -ll
我正在编写一个将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 filen");
    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,LUA_MULTRET,0);
  if (result) {
    fprintf(stderr,"Failed to run script: %sn",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: %sn",schedule);

  // Close lua
  lua_pop(L,1);
  lua_close(L);

  return 0;

}

这是Lua部分:

io.write("lua_test.lua -- will generate schedulen")

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 .. ",n]n"
end

io.write("Returning " .. schedule .. "n");

return schedule

解决方法

AFAIK&在我的5.1.4安装中,该函数位于lualib.h中,而不是lauxlib.h中

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读