Skip to content

Better error for undefined function #92

Closed

Description

@kevinschweikert

I often get {:undefined_function, nil} but it would be really helpful if we could include the function name which Lua was trying to call

Activity

  1. davydog187 commented on Oct 8, 2025

    @davydog187
    Contributor

    Thanks for reporting @kevinschweikert

    I very much agree this error message sucks. We need to make some changes upstream to Luerl in order to fix this

  2. added this to the 1.0.0 milestone on May 28, 2026
  3. davydog187 commented on Jun 15, 2026

    @davydog187
    Contributor

    Done — the undefined-function error now includes the name/value being called (lib/lua.ex:807,848: undefined function '#{inspect(func)}'). The old bare {:undefined_function, nil} is gone.

  4. kevinschweikert commented on Jun 15, 2026

    @kevinschweikert
    ContributorAuthor

    @davydog187 i still get nil

    Mix.install([
      {:lua, github: "tv-labs/lua"}
    ])

    Section

    import Lua
    
    chunk = ~LUA"""
    function foo() 
      return "foo"
    end
    """c
    
    {_, lua} = Lua.eval!(chunk) 
    
    Lua.call_function(lua, [:bar], []) |> dbg()
    [Library/Application Support/livebook/autosaved/2026_06_10/14_10_lq45/untitled_notebook.livemd#cell:3enxehoenz643lpp:11: (file)]
    Lua.call_function(lua, [:bar], []) #=> {:error, "undefined function 'nil'", #Lua<>}
    
    
  5. davydog187 commented on Jul 8, 2026

    @davydog187
    Contributor

    Fixed in #383. Lua.call_function/3 was inspecting the resolved value (nil) instead of the name you looked up. It now routes through the same TypeError the VM raises for an in-Lua call, so it names the callee:

    Call Before After
    call_function(lua, [:bar], []) {:error, "undefined function 'nil'", …} {:error, "attempt to call a nil value (global 'bar')", …}
    call_function(lua, [:x], []) (x=5) {:error, "undefined function '5'", …} {:error, "attempt to call a number value (global 'x')", …}
    call_function!(lua, [:bar], []) Lua runtime error: undefined function 'nil' Full render: message + Suggestion: block
    nested [:t, :missing] undefined function 'nil' attempt to call a nil value (field 'missing')

    The terse call_function/3 reason stays a one-line pcall-parity string; call_function!/3 gets the rich render with a Suggestion: block, matching what you already see for an undefined call made from inside Lua.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions