Add hello world C lib

This commit is contained in:
Enrico Lumetti 2022-05-12 11:03:04 +02:00
parent 8b9eafe94c
commit f457e31740
3 changed files with 24 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
*.luo *.luo
lunaclib/lunaclib.so

4
lunaclib/build.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
cc -shared $(pkg-config --cflags luajit) lunaclib.c $(pkg-config --libs luajit) -o lunaclib.so

19
lunaclib/lunaclib.c Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
#include <lua.h>
#include <lauxlib.h>
static int hello(lua_State* L) {
puts("Hello World!");
return 0;
}
static const struct luaL_Reg lib[] = {
{"hello", hello},
{NULL, NULL}
};
int luaopen_lib (lua_State *L) {
luaL_openlib(L, "lunaclib", lib, 0);
return 1;
}