Added usleep native wrapper

This commit is contained in:
Łukasz Magiera 2016-01-06 17:16:09 +01:00
parent aeb3bf786e
commit e6f07e6cb6
4 changed files with 24 additions and 1 deletions

View File

@ -9,6 +9,7 @@
#define pushctuple(state, name, value) lua_pushstring((state), (name)); lua_pushcfunction((state), (value)); lua_settable((state), -3) #define pushctuple(state, name, value) lua_pushstring((state), (name)); lua_pushcfunction((state), (value)); lua_settable((state), -3)
void run_init(); void run_init();
void luanative_start(lua_State *L);
void setup_modules(lua_State *L); void setup_modules(lua_State *L);
void termutils_start(lua_State *L); void termutils_start(lua_State *L);
#endif #endif

19
src/c/lnative.c Normal file
View File

@ -0,0 +1,19 @@
#include "lupi.h"
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <string.h>
#include <unistd.h>
static int l_sleep (lua_State *L) {
int t = lua_tonumber(L, 1);
usleep(t);
return 0;
}
void luanative_start(lua_State *L) {
lua_createtable (L, 0, 1);
pushctuple(L, "sleep", l_sleep);
lua_setglobal(L, "native");
}

View File

@ -8,9 +8,10 @@
void run_init() { void run_init() {
lua_State *L; lua_State *L;
L = luaL_newstate(); L = luaL_newstate();
luaL_openlibs (L); luaL_openlibs (L);
setup_modules (L); setup_modules (L);
luanative_start (L);
termutils_start (L); termutils_start (L);
int status = luaL_loadstring(L, lua_init); int status = luaL_loadstring(L, lua_init);

View File

@ -5,8 +5,10 @@ function boot.boot()
local w, h = gpu.getResolution() local w, h = gpu.getResolution()
print("r= " .. tostring(w) .. " " .. tostring(h)) print("r= " .. tostring(w) .. " " .. tostring(h))
gpu.fill(0, 0, w, h, " ") gpu.fill(0, 0, w, h, " ")
gpu.set(10, 5, "HHHHHHHHHHHHH")
print("LuPI L2 INIT") print("LuPI L2 INIT")
print("FIXME: boot stub") print("FIXME: boot stub")
native.sleep(1000000)
error("Unable to boot") error("Unable to boot")
end end