this post was submitted on 12 Nov 2023
18 points (90.9% liked)

Programming

17022 readers
327 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

The official documentation isn't 100% clear on things (why am I getting LUA_TNIL for functions?), and the best I can find with some simple web search is kinda relevant stackoverflow (🤮) posts, except they're mostly about calling host functions from Lua side, the rest are things that seem I've nailed so far.

EDIT: Solution was that everyone was using luaL_dofile, while I was forward thinking and used lua_load instead, which isn't a macro, and as such doesn't do an initial lua_pcall. Now I do it manually, and now I get different, but less cryptic and actually documented errors. Now I just have to wrestle with D metaprogramming features (very strong and capable, but is a rabbit hole itself).

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 5 points 10 months ago (1 children)

What do you mean “embedding lua into applications”?

I assume you mean you want an application extensible by user lua script?

You build an API that calls the lua interpreter and passes the script, and reads the output; same as you would for any other scripting language. You define what the inputs should be, create the interface for executing the user defined script through shell commands, and then retrieve the output.

For python you’re going to probably use this:

https://docs.python.org/3/library/subprocess.html#subprocess.check_output

For C# you’re going to use Process

https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output

The complexities arise in your implementation and there’s no single guide.

[–] [email protected] 3 points 10 months ago (1 children)

While lua ships a standalone interpreter, it is very much designed to be embedded directly into an application. This is done by invoking some C apis to load the interpreter into the application’s memory space. OP wants to do that rather than invoking another process and reading the output. When embedding into a host, the host can provide its own objects to be manipulated by the user script allowing for a much better extensibility experience.

[–] [email protected] 1 points 10 months ago

That solution is janky and slow as hell. I'd rather just embed it into my own software, which is mostly done, except it doesn't find functions as functions, but as nil value.