Page 1 of 1

Enumerate "game" object via LUA?

Posted: Thu Feb 07, 2019 4:45 am
by Plawerth
There is no good place for this question. This isn't really modding but more about learning LUA and poking around at stuff.

Is there some way to query the "game" object to list all of its functions? I am trying to get a list of things like "game.player", "game.surface", etc.

Apparently it's a table but using pairs() doesn't do anything.

Code: Select all

/c 
local count = 0
for _ in pairs(game) do
    count = count + 1
    game.player.print("Table entry: " .. _)
end
game.player.print("Total entries: " .. count)
/c local count = 0 for _ in pairs(game) do count = count + 1 game.player.print("Table entry: " .. _) end game.player.print("Total entries: " .. count)

Output:
Table entry: __self
Total entries: 1


So, that's not the right way to do this, if it is even possible..

Re: Enumerate "game" object via LUA?

Posted: Thu Feb 07, 2019 5:40 am
by osldgoth

Re: Enumerate "game" object via LUA?

Posted: Thu Feb 07, 2019 6:58 am
by quyxkh

Code: Select all

/c game.print(game.help())
or if you run it from a command line you can print the help to your terminal with

Code: Select all

/c print(game.help())
where it'll preserve line breaks and you've got the scrollback buffer and all

edit: p.s. Pure lua objects are more convenient for lua accessors, e.g. they allow native lua introspection and all, but garbage-collected structures that would have to be duplicated and synchronized in every mod's lua context (let alone the map globals) aren't an efficient-enough way to run a game engine. Lots of game-engine data is accessible read-only in `game`, for instance if game was provided as pure lua data, synchronizing game.tick and all the rest for every mod would be a nightmare. You could provide the individual items as bare userdata but that has its own problems.