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 syntactic sugar for "__newindex" #16

Open
codyduong opened this issue Jul 17, 2024 · 0 comments
Open

Add syntactic sugar for "__newindex" #16

codyduong opened this issue Jul 17, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request experimental Changes for an unstable/experimental api
Milestone

Comments

@codyduong
Copy link
Owner

codyduong commented Jul 17, 2024

This is an extension of this discussion, which was resolved to support __index

Why support this syntax at all? No need to store r#type as a struct member.

This is for greater discussion on supporting syntactic sugar such as type, format

I have am having trouble with using methods.add_meta_method("__newindex", ... which is holding back most of the work on syntactic sugar. Either convert this to get_type or a method rather than a "field"

If we remove it be sure to remove r#type declarations here

impl<'lua> IntoLua<'lua> for WidgetUserData {
fn into_lua(self, lua: &'lua Lua) -> mlua::Result<mlua::Value<'lua>> {
match self {
WidgetUserData::Clock(sender) => {
let clock_userdata = ClockUserData {
r#type: "Clock".to_string(),
sender: sender,
};
lua.pack(clock_userdata)
}
WidgetUserData::Workspace(_) => {
let workspace_userdata = WorkspaceUserData {
r#type: "Workspace".to_string(),
};
lua.pack(workspace_userdata)
}
WidgetUserData::Box(_) => {
let box_userdata = BoxUserData {
r#type: "Box".to_string(),
};
lua.pack(box_userdata)
}
}
}
}

Originally posted by @codyduong in #9 (comment)

A consideration for adding support is that we must consider method accesses as well (they are themselves a user of "__newindex", which complicates this implementation

@codyduong codyduong mentioned this issue Jul 17, 2024
@codyduong codyduong self-assigned this Aug 10, 2024
@codyduong codyduong added this to the 0.2.0 milestone Aug 16, 2024
@codyduong codyduong added enhancement New feature or request experimental Changes for an unstable/experimental api labels Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request experimental Changes for an unstable/experimental api
Projects
None yet
Development

No branches or pull requests

1 participant