Struct member values #120
Replies: 5 comments 3 replies
|
You could probably format this a bit nicer but here is an example: |
|
Nice. Here is a version which matches Python instantiation syntax more closely: def structToStr(struct: object) -> str:
# example output: 'Vector2(x=3.0, y=4.0)'
name = pr.ffi.typeof(struct).cname.split(' ', 1)[-1]
parts = [name, "("]
sep = ''
for field in dir(struct):
data = struct.__getattribute__(field)
dataStr = str(data)
if dataStr.startswith("<cdata"):
dataStr = structToStr(data)
parts.append(sep)
parts.append(f"{field}={dataStr}")
sep = ', '
parts.append(')')
return ''.join(parts)Any way this could become the default repr() of the various types? If there are objects with too many fields, a |
|
I tried making a Vector2 wrapper class with the hooks to make it "tuple-like" via Looks like specific types are required rather than "list-like" or "tuple-like". Is that something that can be relaxed? I have other wrapper ideas in mind such as various methods and operator overloads. |
|
If the cffi checked for |
|
We found a way of making a vector2 wrapper that seems to work in place of the real vector2: https://github.com/electronstudio/raylib-python-cffi/blob/master/examples/extra/vector2_extended.py |
Uh oh!
There was an error while loading. Please reload this page.
Printing raylib structs gives opaque strings like
<cdata 'struct Color' owning 4 bytes>whether usingstr()orrepr().The type is there, but not the member values. Whether labeled or not, they would be really useful.
Any chance for that?
All reactions