fix video start

This commit is contained in:
2025-06-03 08:42:55 -05:00
parent 2fdf74f6ee
commit cdf8686c64
10 changed files with 72 additions and 103 deletions

View File

@@ -110,8 +110,6 @@ if (!io.exists('.cell')) {
os.exit(1);
}
io.mount(io.realdir("/") + "/.cell/modules")
var use_cache = {}
var BASEPATH = 'scripts/base' + MOD_EXT
@@ -129,20 +127,25 @@ globalThis.use = function use(file, ...args) {
return use_cache[file]
}
// Check for circular dependencies
if (loadingStack.includes(file)) {
let cycleIndex = loadingStack.indexOf(file)
let cyclePath = loadingStack.slice(cycleIndex).concat(file)
throw new Error(
`Circular dependency detected while loading "${file}".\n` +
`Module chain: ${loadingStack.join(" -> ")}\n` +
`Cycle specifically: ${cyclePath.join(" -> ")}`
)
}
// We'll check for circular dependencies after we determine the path
var path = null
if (io.exists(file + MOD_EXT) && !io.is_directory(file + MOD_EXT)) {
// First check if we're loading from a script and look in its directory
if (loadingStack.length > 0) {
var currentScript = loadingStack[loadingStack.length - 1]
if (currentScript.includes('/')) {
var currentDir = currentScript.substring(0, currentScript.lastIndexOf('/'))
// Try the file name as-is in the current directory
var localPath = currentDir + '/' + file + MOD_EXT
if (io.exists(localPath) && !io.is_directory(localPath)) {
path = localPath
}
}
}
// If not found locally, check the normal path
if (!path && io.exists(file + MOD_EXT) && !io.is_directory(file + MOD_EXT)) {
path = file + MOD_EXT
}
@@ -160,18 +163,20 @@ globalThis.use = function use(file, ...args) {
return embed_mod
}
// If we have a script path, check for circular dependency
if (inProgress[path]) {
// Check for circular dependencies using the resolved path
if (path && loadingStack.includes(path)) {
let cycleIndex = loadingStack.indexOf(path)
let cyclePath = loadingStack.slice(cycleIndex).concat(path)
throw new Error(
`Circular dependency detected while loading "${file}".\n` +
`Module chain: ${loadingStack.join(" -> ")}\n` +
`Cycle specifically: ${cyclePath.join(" -> ")}`
)
}
inProgress[path] = true
loadingStack.push(file)
loadingStack.push(path)
// Determine the compiled file path in .cell directory
var compiledPath = ".cell/build/" + io.realdir(path) + "/" + path + '.o'
@@ -232,23 +237,21 @@ globalThis.use = function use(file, ...args) {
return ret
}
var configPath = '.cell/cell.toml'
if (io.exists(configPath)) {
try {
var toml = use('toml')
var configText = io.slurp(configPath)
var config = toml.decode(configText)
// Override defaults with config values
if (config.ENETSERVICE !== undefined)
ENETSERVICE = config.ENETSERVICE
if (config.REPLYTIMEOUT !== undefined)
REPLYTIMEOUT = config.REPLYTIMEOUT
} catch (err) {
log.error(`Failed to load config from ${configPath}: ${err}`)
}
var shop = use('shop')
var config = shop.load_config()
var default_config = {
ar_timer: 60,
actor_memory:0,
net_service:0.1,
reply_timeout:60
}
config.system ??= {}
config.system.__proto__ = default_config
ENETSERVICE = config.system.net_service
REPLYTIMEOUT = config.system.reply_timeout
globalThis.json = use('json')
globalThis.text = use('text')
var time = use('time')
@@ -288,11 +291,6 @@ stone.p = function(object)
return Object.isFrozen(object)
}
var DOCPATH = 'scripts/doc' + MOD_EXT
var script = io.slurp(DOCPATH)
var fnname = "doc"
script = `(function ${fnname}() { ${script}; })`
/*
When handling a message, the message appears like this:
{
@@ -629,7 +627,7 @@ function turn(msg)
send_messages()
}
actor_mod.register_actor(cell.id, turn, cell.args.main)
actor_mod.register_actor(cell.id, turn, cell.args.main, config.system)
overling = cell.args.overling
root = cell.args.root
@@ -762,19 +760,21 @@ if (io.exists(progPath + ACTOR_EXT) && !io.is_directory(progPath + ACTOR_EXT)) {
if (!prog)
throw new Error(cell.args.program + " not found.");
var progDir = io.realdir(prog) + "/" + prog.substring(0, prog.lastIndexOf('/'))
var search = io.searchpath()
//io.unmount(search[1])
var progDir = io.realdir(prog) + "/" + prog.substring(0, prog.lastIndexOf('/'))
io.mount(progDir.replace(/\/+$/, ''))
var progContent = io.slurp(prog)
var prog_script = `(function ${cell.args.program.name()}_start($_, arg) { var args = arg; ${progContent} })`
var val = js.eval(cell.args.program, prog_script)($_, cell.args.arg)
if (val)
throw new Error('Program must not return anything');
log.console("WAYDOWN")
send_messages()
})()