add lua binding (#53)
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user