Skip to content

Commit

Permalink
Convert None dict keys to python.none in "table_from()" (GH-223)
Browse files Browse the repository at this point in the history
Previously resulted in a crash.

Closes #137
  • Loading branch information
Le0Developer authored Apr 3, 2023
1 parent a1383f3 commit 2b569fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lupa/_lupa.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ cdef class LuaRuntime:
for obj in args:
if isinstance(obj, dict):
for key, value in obj.iteritems():
py_to_lua(self, L, key)
py_to_lua(self, L, key, wrap_none=True)
py_to_lua(self, L, value)
lua.lua_rawset(L, -3)

Expand All @@ -447,7 +447,7 @@ cdef class LuaRuntime:
elif isinstance(obj, Mapping):
for key in obj:
value = obj[key]
py_to_lua(self, L, key)
py_to_lua(self, L, key, wrap_none=True)
py_to_lua(self, L, value)
lua.lua_rawset(L, -3)
else:
Expand Down
3 changes: 2 additions & 1 deletion lupa/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,11 @@ def test_create_table_args_kwargs(self):
self.assertEqual(6, len(table))

def test_table_from_dict(self):
table = self.lua.table_from({"foo": 1, "bar": 20, "baz": "spam"})
table = self.lua.table_from({"foo": 1, "bar": 20, "baz": "spam", None: "python.none"})
self.assertEqual( 1, table['foo'])
self.assertEqual( 20, table['bar'])
self.assertEqual("spam", table['baz'])
self.assertEqual("python.none", table[None])

self.assertEqual(0, len(table))

Expand Down

0 comments on commit 2b569fb

Please sign in to comment.