add lua binding (#53)
This commit is contained in:
parent
070f52dda3
commit
683210d02f
29
README.md
29
README.md
@ -154,6 +154,35 @@ fn main() {
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
### ruapu with Lua
|
||||
|
||||
<table>
|
||||
|
||||
<tr><td>
|
||||
|
||||
Compile ruapu library
|
||||
|
||||
```shell
|
||||
# from source code
|
||||
cd lua
|
||||
# lua binding has been tested on Lua 5.2~5.4
|
||||
luarocks make
|
||||
```
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Use ruapu in Lua
|
||||
|
||||
```Lua
|
||||
ruapu = require "ruapu";
|
||||
print(ruapu.supports("mmx"));
|
||||
for _, ext in ipairs(ruapu.rua()) do
|
||||
print(ext);
|
||||
end
|
||||
```
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
<details>
|
||||
<summary>Github-hosted runner result (Linux)</summary>
|
||||
|
||||
|
19
lua/ruapu-0.1-1.rockspec
Normal file
19
lua/ruapu-0.1-1.rockspec
Normal 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
lua/ruapu-binding.c
Normal file
36
lua/ruapu-binding.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user