Skip to content
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

Feature Request: Export additional functions from luerl_heap #171

Open
artman41 opened this issue Feb 5, 2024 · 1 comment
Open

Feature Request: Export additional functions from luerl_heap #171

artman41 opened this issue Feb 5, 2024 · 1 comment

Comments

@artman41
Copy link
Contributor

artman41 commented Feb 5, 2024

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:

  • del_tstruct/2
  • get_tstruct/2

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

  • set_tstruct/3
  • upd_tstruct/3

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
Copy link
Owner

rvirding commented Feb 6, 2024

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

  • #tstruct is an internal implementation detail which is not intended to be seen or accessed from the outside. It is in fact a relatively new implementation detail, only a few years old, and I will quite happily replace it with something else if/when I find a better solution.

  • You have to be very careful not to delete a function which is referenced by something else. This can very easily be done by mistake and can result in either crashing the system when you call a non-existent function or strange behaviour if you get a new unexpected function.

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. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants