Reputation: 51
In C language, we use #include
statement and using
statement in C# to be able to attach its build-in function. But in Lua, we dont need to do anything, then we can use the coroutine
, table
, io
, etc.
Upvotes: 1
Views: 125
Reputation: 5564
The Lua interpreter exports all basic functions and library tables to Lua programs by calling luaL_openlibs before running the program.
EDIT:
Why don't all languages do this?
It's a trade-off. If a language exposes its entire standard library by default, it saves us a lot of boilerplate. On the other hand, it can pollute the namespace, use more memory, and increase startup time. Lua's standard library is small, so it doesn't cost very much. Most compiled languages try to be as lean as possible, so they make us import everything explicitly.
Upvotes: 2
Reputation: 26794
It's because Lua "pre-imports" some of the libraries for you. You can re-configure your copy of Lua to load a different set of libraries. See lualib.h
file in the Lua distribution for the list of pre-loaded libraries.
Upvotes: 4