Problems importing external Lua library

I’m trying to use Luerl to import an external Lua library that claims to be compatible with Lua 5.1-5.4 with no other external dependencies, djot.

There isn’t much documentation on how to load external modules, so I played around a bit.

Given the following test.lua file:

local djot = require("djot")
local input = "This is *djot*"
local doc = djot.parse(input)
local html = djot.render_html(doc)

print(html)

I checked out djot inside /tmp/playground so the Git repo ends up in /tmp/playground/djot. I then tried luerl:evalfile with a custom path, which seems to load all modules, but later gets a weird error:

1> os:putenv("LUA_PATH", "/tmp/playground/?/?.lua;/tmp/playground/djot/?.lua").
true
2>  luerl:evalfile("test.lua", luerl:init()).
{error,function_clause,
    [{luerl_heap,raw_set_table_key,
         [{tref,81},
          <<"s">>,<<"This is ">>,
          {luerl, ...

Is this a bug? Am I using the wrong API?

Not sure how to proceed here. I couldn’t find much documentation on how to load external Lua libraries with luerl…

(cc @DianaOlympos :wink:)

3 Likes

@rvirding Could surely help :slight_smile:

1 Like

Hmm. Could you test test.lua stepwise to see how far down you get. Luerl is generally compatible but some things do pop up which it can’t handle. I have4 never tried djot and I haven’t heard of anyone who has.

Try joining the luerl slack and asking there.

2 Likes

It fails first with the following lines:

local djot = require("djot")
local input = "This is *djot*"
djot.parse(input)

Here’s the stack trace (without the luerl state, let me know if you want it).

1> luerl:evalfile("test.lua", luerl:init()).
{error,function_clause,
    [{luerl_heap,raw_set_table_key, [{tref,81}, <<"s">>,<<"This is ">>, {luerl, ...}],
         [{file, "/tmp/playground/_build/default/lib/luerl/src/luerl_heap.erl"},
          {line,335}]},
     {luerl_lib_basic,rawset,2,
         [{file, "/tmp/playground/_build/default/lib/luerl/src/luerl_lib_basic.erl"},
          {line,227}]},
     {luerl_emul,call_erlfunc,5,
         [{file, "/tmp/playground/_build/default/lib/luerl/src/luerl_emul.erl"},
          {line,767}]},
     {luerl_emul,functioncall,3,
         [{file, "/tmp/playground/_build/default/lib/luerl/src/luerl_emul.erl"},
          {line,319}]},
     {luerl,evalfile,2,
         [{file, "/tmp/playground/_build/default/lib/luerl/src/luerl.erl"},
          {line,55}]},
     {erl_eval,do_apply,7,[{file,"erl_eval.erl"},{line,748}]},
     {shell,exprs,7,[{file,"shell.erl"},{line,691}]},
     {shell,eval_exprs,7,[{file,"shell.erl"},{line,647}]}]}

The invite link is broken. :frowning:

1 Like

Strange, the invite link marked here seems to work for me.

Which branch of Luerl are you using, the one you should use is develop. That is the one I will be working on.

1 Like

For some reason I got redirected to the old Heroku app somewhere. The GitHub link worked fine, thanks.

It’s develop but the error exists in 1.0 from Hex as well.

1 Like

I have found the bug and will push a commit tomorrow. You were the first person to run code which uses the rawset basic library function

4 Likes

Lovely! I’ll be gone for the holidays so expect a slow response. Happy holidays! :confetti_ball:

1 Like

Ah, is that a semicolon in the path?
Shouldn’t it be a colon?

1 Like

I have no clue! :sweat_smile: I scavenged my snippets together from various issues in the repo. There was no tutorial dealing directly with load paths and external libraries.

1 Like

So bug is (hopefully) fixed and commit pushed to develop.

@nzok I am totally missing something here. Which semicolon in which path?

1 Like