fluffos/testsuite/std/present_clone.lpc
Yucong Sun 592dfc0688 Prefer .lpc source extension; rename testsuite to .lpc
Source resolution is now explicit-extension-exact: load_object("/foo.c")
probes only foo.c, never foo.lpc (and vice versa); extension-less names
prefer .lpc and fall back to .c. Object identity stays extension-blind:
object names carry no extension, any spelling finds a loaded object, and
the registry is consulted before the filesystem. The caller's raw
spelling now flows through find_object()/inherit/master/simul_efun loads
instead of being pre-stripped away.

- filename_to_obname and otable basename() strip .lpc too (children())
- save_object() strips either source extension before appending .o
- replace_program()/function_exists() handle both suffixes
- testsuite: all LPC sources renamed to .lpc; runner globs, master
  get_include_path cases, and program-name assertions updated;
  README.md rewritten with the extension rules and suite conventions
- new single/tests/efuns/dual_extension.lpc pins exact-pick, fallback,
  no-crossover, identity, and registry-before-filesystem with .c/.lpc
  fixture pairs in /clone

Verified: ctest 297/297 and driver-autotest x3 (ASan Debug) plus
RelWithDebInfo ctest + autotest.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-09 20:48:48 -04:00

54 lines
1.5 KiB
Text

object present_clone( mixed args... )
{
object *found = ({ }) ;
string source_file ;
object source_ob ;
object env ;
int which ;
if(!sizeof(args)) error("Missing argument 1 to present_clone.\n") ;
if(stringp(args[0])) source_file = args[0] ;
else if(objectp(args[0])) source_ob = args[0] ;
else error("Invalid argument 1 passed to present_clone. Expected object or string, got " + typeof(args[0]) + ".\n") ;
if(sizeof(args) >= 2)
{
if(intp(args[1])) which = args[1] ;
else if(objectp(args[1])) env = args[1] ;
else error("Invalid argument 2 passed to present_clone. Expected object or int, got " + typeof(args[0]) + ".\n") ;
if(sizeof(args) == 3)
{
if(intp(args[2])) which = args[2] ;
else error("Invalid argument 3 passed to present_clone. Expected int, got " + typeof(args[0]) + ".\n") ;
if(sizeof(args) > 3)
{
error("Too many arguments passed to present_clone.\n") ;
}
}
else
{
which = 0 ;
}
}
else
{
env = previous_object() ;
which = 0 ;
}
found = all_inventory( env ) ;
if(!sizeof(found)) return 0 ;
if(source_ob) source_file = base_name(source_ob) ;
found = filter(found, function(object ob, string file) {
return base_name(ob) == file ;
}, source_file) ;
if(which > sizeof(found) - 1 ) return 0 ;
return found[which] ;
}