代码:hello.c
#include <lua.h>
#include <lauxlib.h>
#include <math.h>
#include <stdlib.h> /* For function exit() */
#include <stdio.h> /* For input/output */
#include<string.h>
#include<errno.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
int port( lua_State *L )
{
double d = luaL_checknumber(L, 1);
lua_pushnumber(L, sin(d));
return 1;
}
static const luaL_Reg hello[] = {
{ "port", port },
{ NULL, NULL }
};
int luaopen_hello( lua_State *L )
{
luaL_newlib(L, hello);
return 1;
}
test.lua
local hello = require("hello")
print(hello.port(1))
http://www.linuxidc.com/Linux/2014-09/106763.htm?utm_source=tuicool&utm_medium=referral