Skip to content

Conversation

@dotcarmen
Copy link
Contributor

Previously, the translated file would contain an empty identifier, which is a compiler error. For example, in test output I added, the result would be:

pub const struct_foo_quux = opaque {
    pub const bar1 = foo_quux_bar1;
    pub const @"" = foo_quux_bar2_;
};

@dotcarmen dotcarmen force-pushed the fix-empty-identifier-member branch from 791c0e1 to 8212f13 Compare October 26, 2025 21:29
@dotcarmen
Copy link
Contributor Author

dotcarmen commented Oct 26, 2025

this patch is specifically backwards-compatible. however, I'd personally prefer if the output was something like:

const __MODULE__ = @This();
pub const struct_foo_quux = opaque {
    pub const foo_quux_bar1 = __MODULE__.foo_quux_bar1;
    pub const foo_quux_bar2_ = __MODULE__.foo_quux_bar2;
};

this would prevent compiler errors in cases such as in the Lua API, which has the following declarations:

// https://github.com/lua/lua/blob/fca974486d12aa29bb6d731fdb5b25055157ece8/lua.h#L203
LUA_API const char     *(lua_tolstring) (lua_State *L, int idx, size_t *len);
// https://github.com/lua/lua/blob/fca974486d12aa29bb6d731fdb5b25055157ece8/lauxlib.h#L52
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);

currently, translate-c ignores the second declaration when translating lauxlib.h, since it's declared after the #include that includes the first declaration:

pub const struct_lua_State = opaque {
    pub const tolstring = lua_tolstring;
};

however, users might want to have both declarations available, and not care about the naming.

let me know if this change is agreeable, or if it's acceptable as an option to translate-c instead. i can work on such a patch in either case

@Vexu
Copy link
Member

Vexu commented Oct 27, 2025

Looks like this is a better fix for #202

let me know if this change is agreeable, or if it's acceptable as an option to translate-c instead. i can work on such a patch in either case

I mentioned doing that in the PR that implemented this feature but haven't gotten around to it yet #22 (comment)

@dotcarmen
Copy link
Contributor Author

opened #215 which takes the alternate approach (don't demangle at all)

@dotcarmen dotcarmen force-pushed the fix-empty-identifier-member branch from d55761a to 2d9738a Compare October 28, 2025 20:54
@Vexu Vexu linked an issue Oct 28, 2025 that may be closed by this pull request
@Vexu Vexu closed this in #215 Nov 16, 2025
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.

generates empty identifier when a member function name ends with _

2 participants