Factorio userdata class name api

Post Reply
golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Factorio userdata class name api

Post by golfmiketango »

Although the new is_player api is a nice start, it would be much appreciated if we could just ask an arbitrary userdata object what its factorio API "class" name is, i.e.,:

Code: Select all

function pretty(thing)
  if type(thing) == 'table' and thing.factorio_class then
    return '[Factorio: ' .. thing.factorio_class .. ']'
  else
    ...
  end
end

print(pretty(game))
(output: [Factorio: LuaGameScript])
Perhaps, somehow, modders can already create a big matrix of clever hacks to achieve the equivalent but why not make it easy?

This would be especially helpful for people tackling the initial learning curve of mod design like myself, as we are the ones who are most prone to get mixed up and lose the What The Heck Have I Got a Handle For Here? game.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13202
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Factorio userdata class name api

Post by Rseding91 »

What's the utility of knowing the class type? You can already know what a specific class type is based off what event or method you got it from.
If you want to get ahold of me I'm almost always on Discord.

golfmiketango
Filter Inserter
Filter Inserter
Posts: 549
Joined: Fri Jan 29, 2016 2:48 am
Contact:

Re: Factorio userdata class name api

Post by golfmiketango »

Rseding91 wrote:What's the utility of knowing the class type? You can already know what a specific class type is based off what event or method you got it from.
Well, pretty printing is a good example isn' t it? Lua is dynamically typed so subproblems of this one come up all the time. Especially in debugging, any kind of serialization we might want to do (increasingly important once rcon enters the picture), higher-level Gui framework-design, metatable operator-overload implementations, etc. Basically anywhere we might benefit from being in a dynamically-typed language, we can't, because of mysterious userdata problems.

Bilka
Factorio Staff
Factorio Staff
Posts: 3128
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Factorio userdata class name api

Post by Bilka »

Hey, this was implemented at some point: https://lua-api.factorio.com/latest/Com ... bject_name
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Implemented mod requests”