Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting error "Attempted to index global 'table' (A nil value)" Lua

When I run this code snippet in Lua (using PICO-8 if it helps)

a = {}
table.insert(a,1,'foo')

I get the error

Attempted to index global "table" (a nil value)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

According to the Lua website, this should work (https://www.lua.org/pil/19.2.html).
What am I doing wrong?

>Solution :

Lua was unable to resolve the table part of table.insert. This is most likely because your host environment does not include the table standard library.

As Lua is an "embedded" language, and most of its standard library is optional and may not be available if an environment decides to exclude it.

For PICO-8 in particular:

PICO-8 does not include the Lua standard library, and instead provides
a proprietary collection of global functions.

Source

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading