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

Add Support for Functions #8

Open
hjdivad opened this issue Jun 15, 2022 · 1 comment
Open

Add Support for Functions #8

hjdivad opened this issue Jun 15, 2022 · 1 comment

Comments

@hjdivad
Copy link
Owner

hjdivad commented Jun 15, 2022

local fn_info = debug.getinfo(fn, 's')
fn_info.source --=> @.repl.lua
fn_info.linedefined --=> 6
fn_info.lastlinedefined --=> 8
fn_info.nparams --=> 2
fn_info.isvararg --=> false
fn_info.nups --=> 1

This allows us to add support for functions defined outside of stdin. For a
REPL usecase, this means sending loadfile(<file>)() to the REPL instead of
the lines themselves.

nups ("number of upvalues") can be used to see if the function requires a closure.

With this information we can support functions that:

  1. Do not require closures (i.e. nups == 0)
  2. Are defined somewhere other than stdin
@hjdivad
Copy link
Owner Author

hjdivad commented Jun 15, 2022

It's possible that debug.getupvalue makes even closure functions possible, especially for the limited use case of lua code that all lives in a repl.lua that is sent to a REPL.

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

No branches or pull requests

1 participant