Skip to content

Commit f3ef3cb

Browse files
authored
Fix Lua.Table.as_string with nested tables (#57)
1 parent 5423eba commit f3ef3cb

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

guides/working-with-lua.livemd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
```elixir
66
Mix.install([
7-
{:lua, "~> 0.0.20"}
7+
{:lua, "~> 0.0.21"}
88
])
99
```
1010

lib/lua/table.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ defmodule Lua.Table do
138138
defp format_value(key, value, formatter) do
139139
case formatter.(key, value) do
140140
list when is_list(list) -> "{#{print_table(list, formatter)}}"
141+
map when is_map(map) -> "{#{print_table(map, formatter)}}"
141142
{:userdata, _value} -> inspect("<userdata>")
142143
true -> "true"
143144
false -> "false"

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule Lua.MixProject do
22
use Mix.Project
33

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

77
def project do
88
[

test/lua/table_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ defmodule Lua.TableTest do
5858
~S<{a = 1, b = "~D[2024-09-22]"}>
5959
end
6060

61+
test "it can handle nested maps" do
62+
table = [a: 1, b: 2, c: %{d: %{e: 5}}]
63+
64+
assert Lua.Table.as_string(table) == "{a = 1, b = 2, c = {d = {e = 5}}}"
65+
end
66+
6167
# We can't handle self-referential tables as
6268
# Luerl cannot decode them
6369
@tag :skip

0 commit comments

Comments
 (0)