Pike Module Resolution "Parent lost" Fix
Problem
When organizing Pike code into modules using directories (e.g., LSP.pmod/Intelligence.pmod/Resolution.pike), wrapping the code inside Resolution.pike with an explicit class Resolution { ... } block causes the Pike resolver to fail when instantiating the class via master()->resolv().
The error manifests as:
Parent lost, cannot clone program
Context / Trigger Conditions
- •Structure: A
.pikefile inside a.pmoddirectory (e.g.,pike-scripts/LSP.pmod/Intelligence.pmod/Resolution.pike). - •Code: The
.pikefile contains an outer class wrapper matching the filename. - •Access: Attempting to resolve and clone the class using
master()->resolv("LSP.Intelligence.Resolution")(). - •Error: "Parent lost" indicates the inner class has lost its connection to the parent module context during resolution.
Solution
Remove the outer class wrapper. In Pike, a .pike file inside a module directory is the class definition itself. You do not need (and should not have) an explicit class wrapper around the content.
Before (Incorrect)
File: pike-scripts/LSP.pmod/Intelligence.pmod/Resolution.pike
// This causes "Parent lost" when resolved dynamically
class Resolution {
void create() { ... }
// methods...
}
After (Correct)
File: pike-scripts/LSP.pmod/Intelligence.pmod/Resolution.pike
// The file itself defines the class
void create() { ... }
// methods...
Verification
- •Run a script that uses
master()->resolv()to load the module. - •Attempt to clone it:
program p = master()->resolv("LSP.Intelligence.Resolution"); object o = p(); - •If it succeeds without "Parent lost", the fix is verified.
Notes
- •This behavior is specific to how Pike handles the "program" object returned by
resolv(). - •When you wrap code in a class,
resolv()returns the program for the file, but to get an instance of the inner class, you'd need to clone the file program first, then access the inner program, which is awkward and breaks standard module resolution patterns.
References
- •Pike Module System Documentation (general concept of files as classes)