Skip to content
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

Add methods to set and get custom data for juice agents #258

Closed
wants to merge 1 commit into from

Conversation

fatduckling
Copy link

  • Implemented juice_agent_set_data to allow users to attach custom data to a juice agent.
  • Implemented juice_agent_get_data to retrieve the custom data attached to a juice agent.
  • Updated juice_agent_t structure to include a user_ptr for storing custom data.
  • Added tests to validate the functionality of the new methods.

These changes enable each juice agent to have its own custom data, enhancing flexibility and usability.

- Implemented juice_agent_set_data to allow users to attach custom data to a juice agent.
- Implemented juice_agent_get_data to retrieve the custom data attached to a juice agent.
- Updated juice_agent_t structure to include a user_ptr for storing custom data.
- Added tests to validate the functionality of the new methods.

These changes enable each juice agent to have its own custom data, enhancing flexibility and usability.
Copy link
Owner

@paullouisageneau paullouisageneau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case for this? There is already a user_ptr in juice_config_t, doesn't it suit your needs? It is already passed to every callback so you should not need a getter to retrieve it from the agent.

/* This is a custom field that can be used to store user data for the agent.
* Use the juice_agent_set_data and juice_agent_get_data methods to store and retrieve the data.
*/
void* user_ptr;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference with the existing user_ptr in juice_config_t?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I wanted each agent to have its own (unique) data.

My current implementation uses the same juice_config_t for all the agents.
I just realised that if I create multiple instances of juice_config_t, each having its own unique data, then each agent will also have its own user pointer.
I'll close the PR, thanks

Copy link
Owner

@paullouisageneau paullouisageneau Jun 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK, the config is actually copied for each agent, so you can change it between calls to juice_create(), it won't interfere with already-created agents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants