C Lua ( Lua 5.1-5.3 LuaJIT ):
example.c:
#include <lua.h>
int example_hello(lua_State* L) {
lua_pushliteral(L, "Hello, world!");
return 1;
}
int luaopen_example(lua_State* L) {
lua_newtable(L);
lua_pushcfunction(L, example_hello);
lua_setfield(L, -2, "hello");
return 1;
}
rockpec example-1.0-1.rockspec:
package = "example"
version = "1.0-1"
source = {
url = "." -- not online yet!
}
build = {
type = "builtin",
modules = {
example = "example.c"
}
}
luarocks make. C .
!
Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
> example = require("example")
> print(example.hello())
Hello, world!
>