luv

luv/docs.md at master · luvit/luv
Bare libuv bindings for lua. Contribute to luvit/luv development by creating an account on GitHub.
luv/docs.md at master · luvit/luv favicon https://github.com/luvit/luv/blob/master/docs.md#pseudo-types
luv/docs.md at master · luvit/luv
GitHub - luvit/luv: Bare libuv bindings for lua
Bare libuv bindings for lua. Contribute to luvit/luv development by creating an account on GitHub.
GitHub - luvit/luv: Bare libuv bindings for lua favicon https://github.com/luvit/luv
GitHub - luvit/luv: Bare libuv bindings for lua

cmake で build

luv に CMake が付属しており簡単。

$ cmake -S {LUV_DIR} -B {BUILD_DIR}
$ cmake --build {BUILD_DIR} --config Release

main loop を idle へ

-- Main loop
while app:new_frame() do
gui:update()
app:render(gui.clear_color)
end
local uv = require("luv")
-- Main loop
local idle = uv.new_idle()
idle:start(function()
if not app:new_frame() then
idle:stop()
end
gui:update()
app:render(gui.clear_color)
end)
uv.run("default")

重い処理を thread へ

local ctx = uv.new_work(
on_thread, --work,in threadpool
on_end --after work, in loop thread
)
uv.queue_work(ctx, mp.pack({ ... }))
Error: thread arg not support type 'table' at 2Error: thread arg not support type table at 1Uncaught Error: attempt to call a nil value

thread 間で受け渡しのできる型

threadargs: variable arguments (…) of type nil, boolean, number, string, or userdata

nvim ではそこで messagepack なわけか。

Kyoto Tycoon+Lua-JIT拡張+MessagePack=無敵 経由で The state of MessagePack in Lua をたどり着く。

If you want pure LuaJIT -> luajit-msgpack-pure

たしかに、これだ。

GitHub - catwell/luajit-msgpack-pure: MessagePack for LuaJIT (using FFI, no bindings, V4 API)
MessagePack for LuaJIT (using FFI, no bindings, V4 API) - catwell/luajit-msgpack-pure
GitHub - catwell/luajit-msgpack-pure: MessagePack for LuaJIT (using FFI, no bindings, V4 API) favicon https://github.com/catwell/luajit-msgpack-pure
GitHub - catwell/luajit-msgpack-pure: MessagePack for LuaJIT (using FFI, no bindings, V4 API)
  • Windows なので malloc, free, realloc が cdef できなかったのを修正
  • functioncdata を nil にしてスキップする処理を追加してみた

結果、巨大なテーブルの pack/unpack でブロックしてしまう。 あとスレッド側のエラーハンドリングをしてないので、デバッガはアタッチできないし、何もわからない。 pcall などでエラーメッセージを取得して、失敗した場合はエラーメッセージを投げるようにしてあげる必要がある。

なんとなく、使い方はわかった。 後で、アニメーションシステムを実装するときのインフラにも使えるかもしれない。 OpenGL のレンダースレッドと、シーン更新を分離する。

関連