Skip to content

Commit 21a62ce

Browse files
committed
fix: auto-upcast for package functions, enum casts, stale cache
- Package-level functions now use rugo_upcast helpers (same as DotCall), so passing a QPushButton where a QObject is expected works everywhere - Named enum type casts now detected in reclassified package functions - Stale empty cache dirs are re-fetched instead of treated as cached - Qt example: add Ctrl+Q shortcut, use string interpolation, clean up
1 parent 22aebba commit 21a62ce

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

compiler/codegen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2673,7 +2673,7 @@ func (g *codeGen) generateGoBridgeCall(pkg string, sig *gobridge.GoFuncSig, argE
26732673
// Struct handle unwrapping: extract the inner Go struct from the wrapper.
26742674
if sig.StructCasts != nil {
26752675
if wrapType, ok := sig.StructCasts[i]; ok {
2676-
convertedArgs = append(convertedArgs, fmt.Sprintf("%s.(*%s).v", arg, wrapType))
2676+
convertedArgs = append(convertedArgs, fmt.Sprintf("rugo_upcast_%s(%s).v", wrapType, arg))
26772677
continue
26782678
}
26792679
}

examples/require_go_qt/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main

examples/require_go_qt/main.rugo

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
# rugo build main.rugo -o hello_qt && ./hello_qt
1515

1616
# Require miqt/qt6 directly — the sub-path is part of the require path
17-
require "github.com/mappu/miqt/qt6@v0.13.0" as qt6
17+
require "github.com/mappu/miqt/qt6@v0.13.0"
1818
import "os"
19-
use "conv"
2019

2120
# Rugo-side convenience layer using a hash with lambdas
2221
qt = {
@@ -44,7 +43,7 @@ layout.add_widget(lbl)
4443
btn = qt.button("Click Me")
4544
btn.on_clicked(fn()
4645
count = count + 1
47-
lbl.set_text("Clicked: " + conv.to_s(count) + " times")
46+
lbl.set_text("Clicked: #{count} times")
4847
end)
4948
layout.add_widget(btn)
5049

@@ -54,5 +53,11 @@ quit_btn.on_clicked(fn()
5453
end)
5554
layout.add_widget(quit_btn)
5655

56+
# Ctrl+Q shortcut (QKeySequence::Quit = 65)
57+
shortcut = qt6.new_qshortcut3(65, win)
58+
shortcut.on_activated(fn()
59+
qt.quit()
60+
end)
61+
5762
win.show()
5863
qt.exec()

gobridge/inspect.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,15 @@ func reclassifyWithStructs(f ClassifiedFunc, structWrappers map[string]string, p
535535
sig.FuncTypes[i] = ft
536536
} else {
537537
sig.Params = append(sig.Params, gt)
538+
// Detect named types that need explicit casts (e.g., qt6.StandardKey).
539+
if cast := namedTypeCast(t); cast != "" {
540+
if sig.TypeCasts == nil {
541+
sig.TypeCasts = make(map[int]string)
542+
}
543+
sig.TypeCasts[i] = cast
544+
}
538545
}
539546
}
540-
541547
// Classify returns.
542548
results := f.Sig.Results()
543549
for i := 0; i < results.Len(); i++ {

remote/resolver.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func (r *Resolver) resolveWithLock(rp *remotePath) (string, error) {
260260

261261
// For immutable versions, use the standard needsFetch logic.
262262
if rp.isImmutable() {
263-
if _, err := os.Stat(cacheDir); err == nil {
263+
if info, err := os.Stat(cacheDir); err == nil && isDirWithContent(info, cacheDir) {
264264
// Already cached. Record in lock file for completeness.
265265
sha, err := gitRevParseSHA(cacheDir)
266266
if err == nil {
@@ -321,3 +321,16 @@ func (r *Resolver) resolveWithLock(rp *remotePath) (string, error) {
321321
r.trackResolved(moduleKey, versionLabel)
322322
return finalDir, nil
323323
}
324+
325+
// isDirWithContent returns true if the path is a directory with at least one entry.
326+
// Used to detect stale empty cache directories that should be re-fetched.
327+
func isDirWithContent(info os.FileInfo, path string) bool {
328+
if !info.IsDir() {
329+
return false
330+
}
331+
entries, err := os.ReadDir(path)
332+
if err != nil {
333+
return false
334+
}
335+
return len(entries) > 0
336+
}

0 commit comments

Comments
 (0)