diff --git a/.gitignore b/.gitignore index cf7570c..9f2b876 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ *.luo -lunaclib/lunaclib.so +lunaclib.so diff --git a/lunaclib/build.sh b/build.sh similarity index 100% rename from lunaclib/build.sh rename to build.sh diff --git a/lunaclib.c b/lunaclib.c new file mode 100644 index 0000000..c972313 --- /dev/null +++ b/lunaclib.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +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; +} + diff --git a/lunaclib/lunaclib.c b/lunaclib/lunaclib.c deleted file mode 100644 index 3426d77..0000000 --- a/lunaclib/lunaclib.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include - -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; -} - diff --git a/lunajit.lua b/lunajit.lua index 24669f9..99e7ca5 100644 --- a/lunajit.lua +++ b/lunajit.lua @@ -2,7 +2,7 @@ local readbc = require('readbc') local vm = require('vm') local VM = vm.VM -fp = io.open('tests/test1.luo') +fp = io.open('snippets/test1.luo') header = readbc.read_header(fp) proto = readbc.read_proto(fp) fp:close() diff --git a/tests/generate.sh b/snippets/generate.sh similarity index 100% rename from tests/generate.sh rename to snippets/generate.sh diff --git a/tests/test1.lua b/snippets/test1.lua similarity index 100% rename from tests/test1.lua rename to snippets/test1.lua diff --git a/tests/test2.lua b/snippets/test2.lua similarity index 100% rename from tests/test2.lua rename to snippets/test2.lua diff --git a/tests/test3.lua b/snippets/test3.lua similarity index 100% rename from tests/test3.lua rename to snippets/test3.lua diff --git a/tests/test4.lua b/snippets/test4.lua similarity index 100% rename from tests/test4.lua rename to snippets/test4.lua