Skip to content

Commit

Permalink
Fix Lua.Table.as_string with nested tables (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
davydog187 authored Oct 30, 2024
1 parent 5423eba commit f3ef3cb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion guides/working-with-lua.livemd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

```elixir
Mix.install([
{:lua, "~> 0.0.20"}
{:lua, "~> 0.0.21"}
])
```

Expand Down
1 change: 1 addition & 0 deletions lib/lua/table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ defmodule Lua.Table do
defp format_value(key, value, formatter) do
case formatter.(key, value) do
list when is_list(list) -> "{#{print_table(list, formatter)}}"
map when is_map(map) -> "{#{print_table(map, formatter)}}"
{:userdata, _value} -> inspect("<userdata>")
true -> "true"
false -> "false"
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Lua.MixProject do
use Mix.Project

@url "https://github.com/tv-labs/lua"
@version "0.0.20"
@version "0.0.21"

def project do
[
Expand Down
6 changes: 6 additions & 0 deletions test/lua/table_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ defmodule Lua.TableTest do
~S<{a = 1, b = "~D[2024-09-22]"}>
end

test "it can handle nested maps" do
table = [a: 1, b: 2, c: %{d: %{e: 5}}]

assert Lua.Table.as_string(table) == "{a = 1, b = 2, c = {d = {e = 5}}}"
end

# We can't handle self-referential tables as
# Luerl cannot decode them
@tag :skip
Expand Down

0 comments on commit f3ef3cb

Please sign in to comment.