arcticfox1919 / LuaDardo

A Lua virtual machine written in Dart
Apache License 2.0
174 stars 33 forks source link

Pushing nested tables #14

Open phorcys420 opened 2 years ago

phorcys420 commented 2 years ago

The example on how to push a table is great, but how would I push a table corresponding to the following ?

{name="Alex", mom={name="Mary"}}
IonutParau commented 1 year ago

Like this:

ls.newTable(); // Define main table
ls.newTable(); // Define subtable
ls.pushString("Mary"); // Push string Mary
ls.setField(-2, "name"); // Set subtable's name field to Mary
ls.setField(-2, "mom"); // Set main table's mom field to the subtable
ls.pushString("Alex"); // Push string Alex
ls.setField(-2, "name"); // Set main table's name field to Alex