removed internal functions from accessible via use
Some checks failed
Build and Deploy / build-macos (push) Failing after 5s
Build and Deploy / build-linux (push) Failing after 2m15s
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled

This commit is contained in:
2025-05-25 11:51:01 -05:00
parent 792da2ce4b
commit 9f9dfe03a6
8 changed files with 49 additions and 73 deletions

View File

@@ -326,15 +326,10 @@ function joinServer() {
}
var os = use('os')
var actor = use('actor')
for (var i in actor) console.log(i)
// Set up IO actor subscription
var ioguy = {
__ACTORDATA__: {
id: actor.ioactor()
}
};
var sdl = use('sdl')
var ioguy = sdl.ioguy()
send(ioguy, {
type: "subscribe",

View File

@@ -21,9 +21,18 @@ prosperon.dispatch = function(type, data) {
for (var callback of arr) callback(data)
}
var os = use_embed('os')
var actor_mod = use_embed('actor')
// Get hidden modules from prosperon.hidden before stripping it
var hidden = prosperon.hidden
var actor_mod = hidden.actor
var wota = hidden.wota
var console_mod = hidden.console
var use_embed = hidden.use_embed
var use_dyn = hidden.use_dyn
// Strip hidden from prosperon so nothing else can access it
delete prosperon.hidden
var os = use_embed('os')
var js = use_embed('js')
prosperon.on('SIGINT', function() {
@@ -42,12 +51,12 @@ prosperon.on('SIGSEGV', function() {
var io = use_embed('io')
globalThis.console = use_embed('console')
globalThis.console = console_mod
var RESPATH = 'scripts/modules/resources.js'
var canonical = io.realdir(RESPATH) + 'resources.js'
var content = io.slurp(RESPATH)
var resources = js.eval(RESPATH, `(function setup_resources(){${content}})`).call({})
var resources = js.eval(RESPATH, `(function setup_resources(io){${content}})`).call({}, io)
var use_cache = {}

View File

@@ -17,7 +17,6 @@ if (!delay.name || (delay.name !== 'delay' && !delay.name.includes('delay'))) {
var os = use('os');
var io = use('io');
var render = use('render');
var actor = use('actor');
var transform = use('transform');
var gameConfig = {};

View File

@@ -1,7 +1,3 @@
var io = use_embed('io');
var miniz = use_embed('miniz');
var os = use_embed('os');
Object.defineProperty(Function.prototype, "hashify", {
value: function () {
var hash = new Map()
@@ -18,23 +14,11 @@ Object.defineProperty(Function.prototype, "hashify", {
// Merge of the old resources.js and packer.js functionalities
var Resources = {}
// Determine the shared library extension based on the OS
var so_ext
switch(os.platform()) {
case 'Windows':
so_ext = '.dll'
break
default:
so_ext = '.so'
break
}
// Recognized resource extensions
Resources.scripts = ["js"]
Resources.images = ["qoi", "png", "gif", "jpg", "jpeg", "ase", "aseprite"]
Resources.sounds = ["wav", "flac", "mp3", "qoa"]
Resources.fonts = ["ttf"]
Resources.lib = [so_ext]
// Helper function: get extension from path in lowercase (e.g., "image.png" -> "png")
function getExtension(path) {
@@ -169,11 +153,6 @@ Resources.gatherStats = function(filePaths) {
stats.fonts++
continue
}
// For so_ext, we store it in Resources.lib as ['.so'] or ['.dll'], so match that form
if (Resources.lib.includes('.' + ext)) {
stats.lib++
continue
}
stats.other++
}
return stats
@@ -186,36 +165,4 @@ fonts, libs, or other. Return a stats object with these counts and the total.
:return: { scripts, images, sounds, fonts, lib, other, total }
`
// Create a ZIP of recognized files in a directory, skipping ignored ones, and write to outPath
Resources.pack = function(dir, outPath) {
if (!io.exists(dir))
throw Error("Directory does not exist: " + dir)
var files = Resources.getAllFiles(dir)
var writer = miniz.write(outPath)
for (var fullPath of files) {
try {
var st = io.stat(fullPath)
if (!st.filesize) continue // skip directories
// Path in the ZIP: remove leading dir + '/'
var pathInZip = fullPath.substring(dir.length + 1)
var data = io.slurpbytes(fullPath)
writer.add_file(pathInZip, data)
} catch(e) {
// Optionally handle or log errors
}
}
}
Resources.pack[prosperon.DOC] = `
Create a ZIP archive of all recognized files (skipping those matched by .prosperonignore)
in the specified directory and write it to outPath. Recognized extensions are scripts,
images, sounds, fonts, or libs.
:param dir: The directory to zip.
:param outPath: The path (including filename) for the resulting ZIP file.
:return: None
:raises Error: If the directory does not exist.
`
return Resources

View File

@@ -2873,7 +2873,7 @@ void ffi_load(JSContext *js)
arrput(rt->module_registry, ((ModuleEntry){"io", js_io_use}));
arrput(rt->module_registry, ((ModuleEntry){"os", js_os_use}));
arrput(rt->module_registry, ((ModuleEntry){"actor", js_actor_use}));
// actor module moved to hidden_fn
arrput(rt->module_registry, ((ModuleEntry){"input", js_input_use}));
arrput(rt->module_registry, MISTLINE(time));
arrput(rt->module_registry, ((ModuleEntry){"math", js_math_use}));
@@ -2894,15 +2894,15 @@ void ffi_load(JSContext *js)
arrput(rt->module_registry, MISTLINE(nota));
arrput(rt->module_registry, MISTLINE(enet));
arrput(rt->module_registry, MISTLINE(qr));
arrput(rt->module_registry, MISTLINE(wota));
arrput(rt->module_registry, MISTLINE(crypto));
arrput(rt->module_registry, MISTLINE(blob));
arrput(rt->module_registry, MISTLINE(http));
arrput(rt->module_registry, ((ModuleEntry){"sdl_audio", js_sdl_audio_use}));
arrput(rt->module_registry, MISTLINE(console));
// console module moved to hidden_fn
arrput(rt->module_registry, MISTLINE(rtree));
arrput(rt->module_registry, MISTLINE(sprite));
arrput(rt->module_registry, MISTLINE(transform));
arrput(rt->module_registry, MISTLINE(sdl));
#ifdef TRACY_ENABLE
arrput(rt->module_registry, MISTLINE(tracy));
@@ -2927,8 +2927,7 @@ void ffi_load(JSContext *js)
QJSCLASSPREP_FUNCS(font);
QJSCLASSPREP_FUNCS(datastream);
JS_SetPropertyStr(js, globalThis, "use_dyn", JS_NewCFunction(js,js_os_use_dyn,"use_dyn", 1));
JS_SetPropertyStr(js, globalThis, "use_embed", JS_NewCFunction(js,js_os_use_embed,"use_embed", 1));
// use_dyn and use_embed moved to hidden_fn
JSValue jsobject = JS_GetPropertyStr(js,globalThis, "Object");
JS_SetPropertyStr(js, jsobject, "id", JS_NewCFunction(js, js_os_value_id, "id", 1));
@@ -2954,6 +2953,21 @@ void ffi_load(JSContext *js)
//JS_SetPropertyStr(js,prosp, "version", JS_NewString(js,PROSPERON_VERSION));
//JS_SetPropertyStr(js,prosp,"revision",JS_NewString(js,PROSPERON_COMMIT));
JS_SetPropertyStr(js,prosp,"engine_start", JS_NewCFunction(js,js_os_engine_start, "engine_start", 1));
JSValue hidden_fn = JS_NewObject(js);
// add engine.js-only functions to hidden_fn. It should grab them and then remove so nothing else can use them.
// Add modules that should only be accessible to engine.js
JS_SetPropertyStr(js, hidden_fn, "actor", js_actor_use(js));
JS_SetPropertyStr(js, hidden_fn, "wota", js_wota_use(js));
JS_SetPropertyStr(js, hidden_fn, "console", js_console_use(js));
// Add functions that should only be accessible to engine.js
JS_SetPropertyStr(js, hidden_fn, "use_dyn", JS_NewCFunction(js, js_os_use_dyn, "use_dyn", 1));
JS_SetPropertyStr(js, hidden_fn, "use_embed", JS_NewCFunction(js, js_os_use_embed, "use_embed", 1));
JS_SetPropertyStr(js, prosp, "hidden", hidden_fn);
JS_FreeValue(js,globalThis);
}

View File

@@ -14,7 +14,6 @@ extern prosperon_rt *io_actor;
// External function declarations
JSValue js_actor_delay(JSContext *js, JSValue self, int argc, JSValue *argv);
JSValue js_actor_removetimer(JSContext *js, JSValue self, int argc, JSValue *argv);
JSValue js_os_ioactor(JSContext *js, JSValue self, int argc, JSValue *argv);
JSC_CCALL(os_createactor,
int margc = JS_ArrayLength(js, argv[0]);
@@ -105,7 +104,6 @@ static const JSCFunctionListEntry js_actor_funcs[] = {
MIST_FUNC_DEF(os, register_actor, 2),
MIST_FUNC_DEF(os, unneeded, 2),
MIST_FUNC_DEF(os, destroy, 0),
MIST_FUNC_DEF(os, ioactor, 0),
};
JSValue js_actor_use(JSContext *js) {

View File

@@ -473,4 +473,17 @@ JSValue js_sdl_audio_use(JSContext *js) {
JSValue mod = JS_NewObject(js);
JS_SetPropertyFunctionList(js,mod,js_sdl_audio_funcs,countof(js_sdl_audio_funcs));
return mod;
}
JSValue js_os_ioactor(JSContext *js, JSValue self, int argc, JSValue *argv);
static const JSCFunctionListEntry js_sdl_funcs[] = {
MIST_FUNC_DEF(os, ioactor, 0)
};
JSValue js_sdl_use(JSContext *js)
{
JSValue mod = JS_NewObject(js);
JS_SetPropertyFunctionList(js, mod, js_sdl_funcs, countof(js_sdl_funcs));
return mod;
}

View File

@@ -6,5 +6,6 @@
JSValue js_input_use(JSContext *ctx);
JSValue js_camera_use(JSContext *ctx);
JSValue js_sdl_audio_use(JSContext *ctx);
JSValue js_sdl_use(JSContext *js);
#endif /* QJS_SDL_H */