add lua binding (#53)

This commit is contained in:
Ziyao
2024-02-29 21:37:54 +08:00
committed by GitHub
parent 070f52dda3
commit 683210d02f
3 changed files with 84 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
package = "ruapu"
version = "0.1-1"
source = {
url = "https://github.com/nihui/ruapu.git"
}
description = {
summary = "Detect CPU ISA features with single-file",
homepage = "https://github.com/nihui/ruapu",
license = "MIT"
}
dependencies = {
"lua >= 5.2, <= 5.4"
}
build = {
type = "builtin",
modules = {
ruapu = "ruapu-binding.c"
}
}
+36
View File
@@ -0,0 +1,36 @@
#include<lua.h>
#include<lauxlib.h>
#define RUAPU_IMPLEMENTATION
#include"../ruapu.h"
static int supports(lua_State *l)
{
luaL_checktype(l, 1, LUA_TSTRING);
lua_pushboolean(l, ruapu_supports(luaL_checkstring(l, 1)));
return 1;
}
static int rua(lua_State *l)
{
const char * const *s = ruapu_rua();
lua_newtable(l);
for (int i = 0; s[i]; i++) {
lua_pushstring(l, s[i]);
lua_rawseti(l, -2, i + 1);
}
return 1;
}
static const struct luaL_Reg modRuapu[] = {
{ "supports", supports },
{ "rua", rua },
{ NULL, NULL }
};
int luaopen_ruapu(lua_State *l)
{
ruapu_init();
luaL_newlib(l, modRuapu);
return 1;
}