diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-03-19 14:08:00 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-03-19 14:09:09 +0530 |
| commit | 9e3474b5d8ee4afdd9c03cfb4a151ffebfca36b7 (patch) | |
| tree | db76f6775ac45f53a280477a4776586e6c6f251f /src/LuaRuntime.cpp | |
| parent | 1bd89088f1bb6103a34584ae39157abf2f732742 (diff) | |
| download | null-browser-9e3474b5d8ee4afdd9c03cfb4a151ffebfca36b7.tar.gz null-browser-9e3474b5d8ee4afdd9c03cfb4a151ffebfca36b7.zip | |
Add libuv + luv for lua runtime
Diffstat (limited to '')
| -rw-r--r-- | src/LuaRuntime.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/LuaRuntime.cpp b/src/LuaRuntime.cpp index e4a5289..e66c591 100644 --- a/src/LuaRuntime.cpp +++ b/src/LuaRuntime.cpp @@ -2,9 +2,22 @@ #include "LuaRuntime.hpp" +extern "C" { +#include <luv.h> +// Forward declare luv registration function +// LUALIB_API int luaopen_luv(lua_State *L); +} + LuaRuntime::LuaRuntime() { state = luaL_newstate(); luaL_openlibs(state); + luaopen_luv(state); + + if (luaL_dostring(state, "_G.uv = require'luv'")) { + qDebug() << "Unable to load luv: " << lua_tostring(state, -1); + } else { + qDebug() << "succ"; + } luaL_Reg weblib[] = { {"open", &LuaRuntime::lua_onUrlOpen}, @@ -13,6 +26,34 @@ LuaRuntime::LuaRuntime() { }; luaL_newlib(state, weblib); lua_setglobal(state, "web"); + + // auto pp = R"( + // print('Hello -- '); + // local h = uv.fs_open('foobar', 'w', tonumber('644', 8), function(err, h) + // assert(not err, err); + // print('inside'); + // print(h); + // print(err); + // uv.fs_write(h, 'Hello world'); + // end); + // print(h); + // uv.run(); + // print('-- end'); + // )"; + // auto pp = R"( + // print('Hello -- '); + // local t = uv.new_timer(); + // uv.timer_start(t, 7000, 0, function() + // print('after time') + // end); + // uv.run(); + // print('-- end'); + // )"; + // if (luaL_dostring(state, pp)) { + // qDebug() << "Lua Error: " << lua_tostring(state, -1); + // } else { + // qDebug() << "succ"; + // } } void LuaRuntime::evaluate(QString code) { |
