albertodemichelis / squirrel

Official repository for the programming language Squirrel
http://www.squirrel-lang.org
MIT License
895 stars 149 forks source link

No way to identify fields from methods when iterating a class #217

Open reductor opened 4 years ago

reductor commented 4 years ago

Currently when iterating a class with sq_next you get both fields and methods, there is no way to differentiate between what is a _defaultvalues from a class, the only way to identify them is based on the type, however this also does not let you identify static vs non-static

albertodemichelis commented 4 years ago

There is no official way to identify a instance field from a static field at the moment. The handle returned by sq_getmeberhandle has this information encoded into it but is not documented. The member handle is an integer where the least significative 24 bits is an index of the field and the 8 most significative bits are set to 0x01 if is a static field/method and to 0x02 if is an instance field. eg. isstaticormethod = (handle&0xFF000000) == 0x01000000
isinstancefield = (handle&0xFF000000) == 0x02000000

Probably adding a function for this wouldn't be a bad idea.