lunajit/lunaclib.c

32 lines
648 B
C

#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;
}