-
-
Notifications
You must be signed in to change notification settings - Fork 43
What to implement for a type to get tostring() or concatenate functionality? #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hmm, strange! local entity = world.spawn()
print(tostring(entity))
print(entity) works fine and prints: <Reference to Allocation(313)(bevy_ecs::entity::Entity) -> bevy_ecs::entity::Entity>
<Reference to Allocation(313)(bevy_ecs::entity::Entity) -> bevy_ecs::entity::Entity> however trying: print("a " .. entity) results in:
which I believe to be expected behaviour in Lua, but do correct me if I am wrong, an alternative is using format strings: local entity = world.spawn()
print(string.format("I am an entity: %s.", entity)) which prints:
|
I am not sure why you do not have a |
Thank you. That's helpful to know. Hmm, I may not have added that plugin. I was trying to do it without taking in the whole Bevy Lua API. I'll try with it and see if that resolves the issue. Without that plugin for my own custom struct, how could I achieve the tostring behavior? |
I added the plugin and it behaves better! Given this code: local e = ent(id) -- e is a Val<Entity>
print_ent(e) -- my work-around.
world.info("entity tostring "..tostring(e))
-- world.info("entity "..e) -- doesn't work, probably bad Lua.
world.info("entity display_ref "..e:display_ref())
world.info("entity display_value "..e:display_value())
world.info("entity "..tostr(e._1)) Here's the log:
The above code all works except the last line with I'm happy to write a custom type that will do its own Lua Thanks for your help. |
Ah I see! Coincidentally I am working on refactoring the plugin system + adding more fine grained feature flags: #408. As for printing say the index you can use In general though if you wanted to change how types behave on I am planning on eventually improving the printing in general, in this case for example, we could hardcode an override for With the way things are implemented, you can't really have a custom mlua type as everything is either represented as a lua primitive, or a |
Problem
I'd like to be able to pass
Entity
around in Lua, and I can withVal<Entity>
, but I'd also like to be able to calltostring()
on that value, but what happens currently is this.Example for tostring
For this code:
Example for concatenation
And for concatenation I get this.
I'm happy to wrap this value in a custom time
struct MyEntity(Entity)
.Solution
I'd like for either
Debug
orDisplay
to be available in Lua'stostring()
and concatenate functionality.Alternative Solution
I can pass the value to myself, and register a
entity_tostring()
method implemented in Rust do what I want, but that feels off.The text was updated successfully, but these errors were encountered: