syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
How does Lua store packages?

The docs explain that Lua stores packages in Lua tables.

I know about a package called io and that it has a function named read().

I created a variable called mytable and set it equal to keyword: 'io'.
mytable = io
Next, I looked for an element in that table named: 'read'
elmnt = mytable['read']
Lua did not issue an error so that was a good sign.

Then I asked Lua to tell me what type of object is at mytable['read']
type(elmnt)
Here is a screen-dump:
dan@hp ~/ks/b/lua $
dan@hp ~/ks/b/lua $
dan@hp ~/ks/b/lua $ lua
Lua 5.3.0  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> mytable = io
> elmnt = mytable['read']
> type(elmnt)
function
>
> os.exit()
dan@hp ~/ks/b/lua $
dan@hp ~/ks/b/lua $

So, it is possible to interact with a Lua package as if it is a table.

Why?

Because it actually is a table.

syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me