rvirding / luerl

Lua in Erlang
Apache License 2.0
1.02k stars 140 forks source link

Feature Request: Export additional functions from luerl_heap #171

Open artman41 opened 5 months ago

artman41 commented 5 months ago

For the idea I was testing to simulate what I asked in #169 , I had to use erlang.mk's autopatch feature to export the following functions in luerl_heap.erl:

I think, if these are exported, it'd also be beneficial to export these:

For context of how I am using these functions, please see the get_tstruct usage & del_tstruct usage 😄


The idea is to load a Lua file, execute the returned #funref{} and then remove it using del_tstruct/2 from the #luerl.fncs tstruct which leaves the state with only the functions defined in the luafile.

I then use get_tstruct/2 to get the #lua_func{} record of the defined functions, which allows me to access the #lua_func.anno field containing the File & Name of the function.

If you need more context on why I need this, please let me know 👍

I'm happy to submit an MR myself as long as you're comfortable with this change 😄

rvirding commented 5 months ago

I would sincerely recommend that you don't try to solve your problem in this way. This for at least these reasons:

My suggestion for this problem is that after you have called the F function you call the garbage collector, luerl:gc/1 or luerl_new:gc/1, which will remove the function if it is not referenced. And also clean up any other unused data.

As you can guess I will not add those functions. 😄