Skip to content

How do I get the class name of a specific object? #11

Answered by kasperl
kasperl asked this question in Q&A
Discussion options

You must be logged in to vote

Toit programs use class ids (small integers) instead of class names at runtime. This is to save space on memory constrained devices like the ESP32, where Toit programs are stripped of their unnecessary debug information. The information can easily be preserved in a snapshot file, where it can be queried through the tools/snapshot.toit utility code.

Getting the class id

Sometimes, it is useful to get the class name of a specific object or to translate class ids to class names.
If you write this code and run it:

class MyExampleClass:
  // Deliberately left empty.

main:
  x := MyExampleClass
  print x

you will see something along the lines of an instance with class-id 31 printed. Another w…

Replies: 1 comment

Comment options

kasperl
Nov 23, 2021
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by floitsch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant