Skip to content

Lua.call_function/3 expected to return Lua.RuntimeException instead of string with ANSI codes #342

Closed

Description

@kevinschweikert
import Lua

chunk = ~LUA"""
function foo() 
  for i in pairs("asdf") do
    print(i)
  end
end
"""c

{_, lua} = Lua.eval!(chunk) 

Lua.call_function(lua, [:foo], [])
{:error, "\e[2mat -no-source-:\e[0m\n\n  bad argument #1 to 'pairs' (table expected, got string)", #Lua<>}

Expected an error like:

** (Lua.RuntimeException) Lua runtime error: at <eval>:1:

  bad argument #1 to 'pairs' (table expected, got string)
    (lua 1.0.0-rc.2) lib/lua/vm.ex:26: Lua.VM.execute/2
    (lua 1.0.0-rc.2) lib/lua.ex:532: Lua.eval!/3
    #cell:6inzfzpsr4xp5ehh:9: (file)

like from Lua.eval!/1

import Lua

chunk = ~LUA"""
for i in pairs("asdf") do
  print(i)
end
"""

Lua.eval!(chunk) 

Activity

  1. kevinschweikert commented on Jun 10, 2026

    @kevinschweikert
    ContributorAuthor

    Running on:

    Mix.install([
      {:lua, "~> 1.0.0-rc.2"}
    ])
  2. kevinschweikert commented on Jun 10, 2026

    @kevinschweikert
    ContributorAuthor

    Duplicate of #336

  3. kevinschweikert commented on Jun 10, 2026

    @kevinschweikert
    ContributorAuthor

    Also, why is it no source instead of line 2?

  4. kevinschweikert commented on Jun 12, 2026

    @kevinschweikert
    ContributorAuthor

    Hey @davydog187, i probably did not transport my thinking well enough. Why can't we just have the full error struct instead of the string error?

    import Lua
    
    chunk = ~LUA"""
    function foo() 
      for i in pairs("asdf") do
        print(i)
      end
    end
    """c
    
    {_, lua} = Lua.eval!(chunk) 
    
    Lua.call_function(lua, [:foo], []) |> dbg()

    Could return:

    {:error, %Lua.RuntimeException{...}, lua}

    Then we still can print it with Lua.RuntimeException.message(ex) or define a custom way to represent the error back to the user. With a string we loose all metadata like line, source or original

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions