tv-labs / lua

The most ergomonic interface to Luerl in Elixir
https://hexdocs.pm/lua/
Apache License 2.0
71 stars 0 forks source link

Consider LUA sigil turning script into chunk #35

Closed Papipo closed 2 months ago

Papipo commented 3 months ago

I think that given that chunks are portable and don't need a state, it might be interesting to use luerl to turn ~LUA usages into Lua chunks. After all, it's inevitable that they will be loaded at some point, so why not have them converted to chunks already?

davydog187 commented 3 months ago

@Papipo i was planning on supporting this via a sigil modifier, e.g.

~LUA"foo()"c

What do you think?

Papipo commented 3 months ago

Mmm, the only problem I see is that if there are functions that can receive both a string and a chunk you might forget to add the modifier and just carry strings instead of chunks.

davydog187 commented 3 months ago

Well, the reason why I didn't do this to start is that the sigil would need to return a tuple of the chunk and the Lua state, similar to Luerl.do

Given that the shape of the return value is much different, I'm not sure it's so much of a concern

Papipo commented 2 months ago

Ah, true. I was thinking about luerl_comp.string, which doesn't need state. It might not be considered public API, though, but I think it's pretty slick to be able to carry portable chunks around.

There is also the option of making chunk the default and string the modifier. But that only makes sense if you can get the chunk without state (via the function stated above).