From 9e3474b5d8ee4afdd9c03cfb4a151ffebfca36b7 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Wed, 19 Mar 2025 14:08:00 +0530 Subject: Add libuv + luv for lua runtime --- src/LuaRuntime.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/LuaRuntime.cpp') 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 +// 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) { -- cgit v1.3.1