function decide(request)
return iocaine.decision.Passthrough("foo")
end
❯ cargo run -- runtime decide
Anarchism("foo")
Awoo!
function decide(request)
return iocaine.decision.Passthrough("foo")
end
❯ cargo run -- runtime decide
Anarchism("foo")
Awoo!
Hah, the first bullshit generator binding was a bit of a pain, the second one was a breeze.
Marvel at this beautiful thing!
function output(request, decision)
local rng = iocaine.generators.rng:from_seed(request.path);
local fjdata = iocaine.file.read("tmp/fakejpeg.msgpack");
local fj = iocaine.generators.FakeJpeg(fjdata);
local body = fj:generate(rng)
local response = iocaine.http.Response(body);
response:set_header("content-type", "image/jpeg")
return response
end
This is the kind of image that looks better blurred.
Mkay, most garbage generators have Lua bindings now. They're not good, but they more or less work.
But it turns out, I coded the template support very Roto-bound, so I have to rethink how I do the context handling.
Mkay, I have a.. kind of workaround. Now the trouble is figuring out how to translate a Lua values to Upon. Tables, in particular, are a problem, because in Lua, there are no separate types for List and Table. A list is simply an integer-indexed table.
There we go, that's mostly taken care of too.
Now another pass for error handling, because I'm returning a lot of runtime errors that should be more gracefully handled instead.
local foo, err = iocaine.file.read("/blah")
if err ~= nil then
print(err:wrap("hi"):report())
end
=>
× hi
├─▶ failed to read /blah
╰─▶ No such file or directory (os error 2)
Now to bubble this up to the Rust side!
function decide(request)
local err = iocaine.Error("teh root cause")
:help("I am helpful!")
:code("[foo:bar]")
:url("https://example/")
:wrap("wrapping")
return nil, err
end
=>
❯ cargo run -q -- runtime decide
Error: [foo:bar] (https://example/)
× Failed to run `decide()` for http-server `default`
├─▶ wrapping
╰─▶ teh root cause
help: I am helpful!
Neat, neat.
-- entire contents of main.lua
return iocaine.Error("boo")
=>
❯ cargo run -q -- runtime decide
Error: × Failed to load Lua script: ./share/scripts/main.lua
╰─▶ boo
Mkay, one thing left: module support for Lua.
Mppfngh. Bindings are boring, but I'm like... halfway through!