Reputation: 9
To be clear, this is not a how do I do X? , I am confused X is not working question. It is a, wow, I am doing X, I don't understand why does doing X work kind of question. I am very new with scripting languages and I am trying to make some scripts for a server for a really old game, Gothic 2. Needless to get into detail there, but I realised that my scripts are calling all these functions (that I'm copy pasting from the wiki page of the server framework) and they all just run. My scripts have no 'require X' statements in them. How can the Lua interpreter see these functions?
Upvotes: 0
Views: 181
Reputation: 473547
Lua isn't like Python or C or other languages, where each file lives in its own universe almost entirely separate from other files, with the only connections between files created by explicit request. In Lua, any identifier which does not represent a local in the scope of that identifiers usage represents an access to the global environment table. And that table works just like any other table in Lua: you access the named key in that table.
Therefore, any value accessible through that global environment at the time that Lua statement is executed can be used in that statement.
If the C environment that is running your Lua script sticks a bunch of functions in the global environment, then any Lua script it runs can access them. This is likely what is happening in that game.
Upvotes: 2