最近在学 lua,今天在网上找了个 lua 调用 C 的例子学习,例子的代码如下:
#include <math.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
static int l_sin (lua_State *L)
{
double d = luaL_checknumber(L, 1);
lua_pushnumber(L, sin(d));
return 1;
}
static const struct luaL_reg mylib [] = {
{"lsin", l_sin},
{NULL, NULL}
};
int luaopen_mylib(lua_State *L)
{
luaL_openlib(L, "mylib1", mylib, 0);
return 1;
}
编译时报“mylib.c:14: 错误:数组元素的类型不完全”的错,提示“static const struct luaL_reg mylib [] = {” 这一行的代码出错,网上找了下说 GCC 4.0 以上版本,结构要先定义再用。不过本人 C 盲,想问下这个错该怎样改呢,先多谢了。
测试环境:
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
gcc 版本 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
#include <math.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
static int l_sin (lua_State *L)
{
double d = luaL_checknumber(L, 1);
lua_pushnumber(L, sin(d));
return 1;
}
static const struct luaL_reg mylib [] = {
{"lsin", l_sin},
{NULL, NULL}
};
int luaopen_mylib(lua_State *L)
{
luaL_openlib(L, "mylib1", mylib, 0);
return 1;
}
编译时报“mylib.c:14: 错误:数组元素的类型不完全”的错,提示“static const struct luaL_reg mylib [] = {” 这一行的代码出错,网上找了下说 GCC 4.0 以上版本,结构要先定义再用。不过本人 C 盲,想问下这个错该怎样改呢,先多谢了。
测试环境:
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
gcc 版本 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
