Add C function u64_to_num
This commit is contained in:
parent
f457e31740
commit
5aa1a031fa
|
|
@ -1,2 +1,2 @@
|
||||||
*.luo
|
*.luo
|
||||||
lunaclib/lunaclib.so
|
lunaclib.so
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
|
|
||||||
|
static int u64_to_num(lua_State* L) {
|
||||||
|
#ifndef LUA_NUMBER_DOUBLE
|
||||||
|
#error Lua must be compiled with number as a double floating point
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const uint64_t h1 = luaL_checkint(L, 1);
|
||||||
|
const uint64_t h2 = luaL_checkint(L, 2);
|
||||||
|
|
||||||
|
const uint64_t stacked = (h2 << 32) | h1;
|
||||||
|
|
||||||
|
double res = *(double *)((char *)&stacked);
|
||||||
|
lua_pushnumber(L, res);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct luaL_Reg lib[] = {
|
||||||
|
{"u64_to_num", u64_to_num},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
int luaopen_lunaclib(lua_State *L) {
|
||||||
|
luaL_openlib(L, "lunaclib", lib, 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -2,7 +2,7 @@ local readbc = require('readbc')
|
||||||
local vm = require('vm')
|
local vm = require('vm')
|
||||||
local VM = vm.VM
|
local VM = vm.VM
|
||||||
|
|
||||||
fp = io.open('tests/test1.luo')
|
fp = io.open('snippets/test1.luo')
|
||||||
header = readbc.read_header(fp)
|
header = readbc.read_header(fp)
|
||||||
proto = readbc.read_proto(fp)
|
proto = readbc.read_proto(fp)
|
||||||
fp:close()
|
fp:close()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue