# Problems importing external Lua library

**URL:** <https://erlangforums.com/t/problems-importing-external-lua-library/2184>\
**Category:** Luerl Forum\
**Tags:** luerl-questions\
**Created:** [December 17, 2022, 2:55pm UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184 "2022-12-17T14:55:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![eproxus](https://erlangforums.com/user_avatar/erlangforums.com/eproxus/32/452_2.png) [@eproxus](https://erlangforums.com/u/eproxus)\
**Post date:** [December 17, 2022, 2:55pm UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/1 "2022-12-17T14:55:42Z")

</div>

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](https://github.com/jgm/djot#installing).

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

Given the following `test.lua` file:

```nohighlight
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:

```erlang
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 😉)

---

<div class="post-metadata">

**Author:** ![starbelly](https://erlangforums.com/user_avatar/erlangforums.com/starbelly/32/209_2.png) [@starbelly](https://erlangforums.com/u/starbelly)\
**Post date:** [December 17, 2022, 7:53pm UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/2 "2022-12-17T19:53:09Z")

</div>

@rvirding Could surely help 🙂

---

<div class="post-metadata">

**Author:** ![rvirding](https://erlangforums.com/user_avatar/erlangforums.com/rvirding/32/178_2.png) [@rvirding](https://erlangforums.com/u/rvirding)\
**Post date:** [December 17, 2022, 10:23pm UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/3 "2022-12-17T22:23:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![eproxus](https://erlangforums.com/user_avatar/erlangforums.com/eproxus/32/452_2.png) [@eproxus](https://erlangforums.com/u/eproxus)\
**Post date:** [December 18, 2022, 12:03pm UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/4 "2022-12-18T12:03:14Z")

</div>

> [@rvirding](#):
>
> 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.

It fails first with the following lines:

```lua
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).

```erlang
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}]}]}

```

> [@rvirding](#):
>
> Try joining the luerl slack and asking there.

The invite link is broken. ☹

---

<div class="post-metadata">

**Author:** ![rvirding](https://erlangforums.com/user_avatar/erlangforums.com/rvirding/32/178_2.png) [@rvirding](https://erlangforums.com/u/rvirding)\
**Post date:** [December 19, 2022, 12:06am UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/5 "2022-12-19T00:06:15Z")

</div>

Strange, the invite link marked [here](https://erlef.org/slack-invite/luerl) 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.

---

<div class="post-metadata">

**Author:** ![eproxus](https://erlangforums.com/user_avatar/erlangforums.com/eproxus/32/452_2.png) [@eproxus](https://erlangforums.com/u/eproxus)\
**Post date:** [December 20, 2022, 7:47am UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/6 "2022-12-20T07:47:48Z")

</div>

> [@rvirding](#):
>
> Strange, the invite link marked [here](https://erlef.org/slack-invite/luerl) seems to work for me.

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

> [@rvirding](#):
>
> Which branch of Luerl are you using, the one you should use is `develop`. That is the one I will be working on.

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

---

<div class="post-metadata">

**Author:** ![rvirding](https://erlangforums.com/user_avatar/erlangforums.com/rvirding/32/178_2.png) [@rvirding](https://erlangforums.com/u/rvirding)\
**Post date:** [December 20, 2022, 4:54pm UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/7 "2022-12-20T16:54:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eproxus](https://erlangforums.com/user_avatar/erlangforums.com/eproxus/32/452_2.png) [@eproxus](https://erlangforums.com/u/eproxus)\
**Post date:** [December 20, 2022, 8:58pm UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/8 "2022-12-20T20:58:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nzok](https://erlangforums.com/letter_avatar_proxy/v4/letter/n/4af34b/32.png) [@nzok](https://erlangforums.com/u/nzok)\
**Post date:** [December 21, 2022, 4:11am UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/9 "2022-12-21T04:11:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eproxus](https://erlangforums.com/user_avatar/erlangforums.com/eproxus/32/452_2.png) [@eproxus](https://erlangforums.com/u/eproxus)\
**Post date:** [December 21, 2022, 5:35am UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/10 "2022-12-21T05:35:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rvirding](https://erlangforums.com/user_avatar/erlangforums.com/rvirding/32/178_2.png) [@rvirding](https://erlangforums.com/u/rvirding)\
**Post date:** [December 21, 2022, 3:24pm UTC](https://erlangforums.com/t/problems-importing-external-lua-library/2184/11 "2022-12-21T15:24:36Z")

</div>

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

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