-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to hook into require #34
Comments
Alternatively, creating a separate function (ie. |
This works, I can return anything from the imported script: defmodule ErluaTest do
use ExUnit.Case
doctest Erlua
import Lua
defmodule Custom do
@imports %{
"custom" => ~LUA"""
return {
greet = function(name)
print("Printed hello, " .. name)
end,
template = function(name)
return "Templating hello, " .. name
end
}
"""
}
def import([], [path], state) do
{:ok, ret, state} = Luerl.New.do(state, @imports[path])
{ret, state}
end
end
test "Loading lua scripts dynamically" do
entrypoint = ~LUA"""
print("I am the entrypoint")
local imported = import("custom")
imported.greet("world")
print("gonna print a rendered template: " .. imported.template("world"))
"""
result =
Lua.new()
|> Lua.set!([:import], {Custom, :import, []})
|> Lua.eval!(entrypoint)
end
end But as you can see I had to use Luerl |
Hello @Papipo, I'm still thinking about ways to do this. I'll get back to you |
Hi!
I have this app in which users can provide their lua scripts. I don't have those in the filesystem so I need to intercept
require
calls somehow (I will be returning them from the database or as chunks from ETS).An option is to override
require
itself, but I think that adding asearcher
after the preload one is more lua-esque.In case it's better to just override
require
, how would yo approach returning preloaded modules?Basically I don't know if luerl provides a mechanism to hook into require and if we can wrap it in this lib.
Thanks!
The text was updated successfully, but these errors were encountered: