Skip to content

Add Support for Functions #8

@hjdivad

Description

@hjdivad
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions