nurpax / slimgui

ImGui bindings
3 stars 0 forks source link

ini_filename memory references #1

Open nurpax opened 3 weeks ago

nurpax commented 3 weeks ago

This pattern probably isn't correct:

        .def_prop_rw("ini_filename",
            [](ImGuiIO& io) { return io.IniFilename; },
            [](ImGuiIO& io, nb::handle filename) {
                // TODO what about the lifetime of io.IniFilename?
                const char* fname = !filename.is_none() ? nb::cast<const char *>(filename) : nullptr;
                io.IniFilename = fname;
            },
            "ini_filename"_a.none(),
            nb::for_getter(nb::sig("def ini_filename(self, /) -> str | None")),
            nb::for_setter(nb::sig("def ini_filename(self, filename: str | None, /) -> None"))
        )

I don't think there's anything keeping the ini_filename string alive?

Perhaps ImGuiIO needs some kind of a wrapper class too? I guess it would be possible to inherit a WrappedIO from slimgui.IO and override the property access?

nurpax commented 3 weeks ago

See 349808993459f0cb789c516633e915a75a09f8fc for reference.

Defining a similar wrapper around slimgui_ext.IO would work but how to pass most of the property accesses down to the base class without breaking typing?