Let a Rex file wrap a C header with the same name

Structs from C headers get their own table names, so raylib.rex can
wrap "raylib.h" and still have its own Color. Ignore Opcode's
.opcode file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Your NameandClaude Opus 5.5 committed 2026-11-08 14:08:46 +01:00
1 parent fc911ec809
commit a68c720755
5 files changed
+36 -8

No files matched your search

+11 -5
View File
@@ -1111,12 +1111,12 @@ impl Checker {
fn global_key(&self, e: &Expr) -> Option<String> {
match &e.kind {
ExprKind::Ident(n) => match self.c_item(n) {
Some(i) => Some(format!("{}.{n}", self.clibs[i].prefix)),
Some(i) => Some(c_key(&self.clibs[i].prefix, n)),
None => Some(self.q(n)),
},
ExprKind::Field { expr, name } => match self.alias_target(expr)? {
Target::User(p) => Some(format!("{p}.{name}")),
Target::C(i) => Some(format!("{}.{name}", self.clibs[*i].prefix)),
Target::C(i) => Some(c_key(&self.clibs[*i].prefix, name)),
_ => None,
},
_ => None,
@@ -1173,7 +1173,7 @@ impl Checker {
CTy::Str => Ty::Str,
CTy::Handle(n) if n == "pointer" => Ty::CPtr("pointer"),
CTy::Handle(n) => Ty::CPtr(Box::leak(format!("{}.{n}", self.clibs[lib].prefix).into_boxed_str())),
CTy::Struct(n) => Ty::Struct(self.structs.get(&format!("{}.{n}", self.clibs[lib].prefix))?.name),
CTy::Struct(n) => Ty::Struct(self.structs.get(&c_key(&self.clibs[lib].prefix, n))?.name),
CTy::Ptr { .. } | CTy::Unsupported(_) => return None,
})
}
@@ -1183,13 +1183,13 @@ impl Checker {
for li in 0..self.clibs.len() {
let prefix = self.clibs[li].prefix.clone();
for s in self.clibs[li].structs.clone() {
let key = format!("{prefix}.{}", s.name);
let key = c_key(&prefix, &s.name);
let name: &'static str = Box::leak(key.clone().into_boxed_str());
self.structs.insert(key.clone(), StructInfo { name, fields: Vec::new(), methods: HashMap::new(), span: Span::default() });
self.c_structs.insert(key, s.c.clone());
}
for s in self.clibs[li].structs.clone() {
let key = format!("{prefix}.{}", s.name);
let key = c_key(&prefix, &s.name);
let fields: Vec<(String, Ty)> =
s.fields.iter().map(|(n, t)| (n.clone(), self.c_type(li, t).unwrap_or(Ty::CPtr("pointer")))).collect();
self.structs.get_mut(&key).unwrap().fields = fields;
@@ -4168,6 +4168,12 @@ fn check_mutating_calls(funcs: &[HFunc]) -> PResult<()> {
Ok(())
}
/// The table name of a struct from a C header. It is marked so a file of the user's with the
/// same name as the header (a `raylib.rex` wrapping "raylib.h") can have types with the same names.
fn c_key(prefix: &str, name: &str) -> String {
format!("{}{prefix}.{name}", crate::types::C_MARK)
}
/// The name in `names` closest to `name`, if one is close enough to be a likely typo.
fn similar<'a>(name: &str, names: &[&'a str]) -> Option<&'a str> {
fn dist(a: &str, b: &str) -> usize {