mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-17 16:53:13 +00:00
Updated behavior of getJSModule so that the order of precedence matches the recent changes to require()
This commit is contained in:
@@ -55,36 +55,41 @@ duk_ret_t ILibDuktape_ModSearch_GetJSModule(duk_context *ctx, char *id)
|
|||||||
}
|
}
|
||||||
duk_pop(ctx); // ...
|
duk_pop(ctx); // ...
|
||||||
|
|
||||||
retVal = ILibHashtable_Get(table, ILibDuktape_ModSearch_ModuleFile, id, idLen);
|
|
||||||
if (retVal == NULL)
|
|
||||||
{
|
|
||||||
duk_push_heap_stash(ctx);
|
|
||||||
char *mpath;
|
|
||||||
duk_size_t mpathLen;
|
|
||||||
mpath = Duktape_GetStringPropertyValueEx(ctx, -1, ILibDuktape_ModSearch_ModulePath, NULL, &mpathLen);
|
|
||||||
duk_pop(ctx);
|
|
||||||
|
|
||||||
char *fileName = ILibMemory_AllocateA(idLen + 4 + mpathLen + 1);
|
duk_push_heap_stash(ctx);
|
||||||
if (mpath == NULL)
|
char *mpath;
|
||||||
{
|
duk_size_t mpathLen;
|
||||||
sprintf_s(fileName, idLen + 4, "%s.js", id);
|
mpath = Duktape_GetStringPropertyValueEx(ctx, -1, ILibDuktape_ModSearch_ModulePath, NULL, &mpathLen);
|
||||||
}
|
duk_pop(ctx);
|
||||||
else
|
|
||||||
{
|
char *fileName = ILibMemory_AllocateA(idLen + 4 + mpathLen + 1);
|
||||||
sprintf_s(fileName, idLen + 5 + mpathLen, "%s/%s.js", mpath, id);
|
if (mpath == NULL)
|
||||||
}
|
{
|
||||||
int dataLen = ILibReadFileFromDiskEx(&retVal, fileName);
|
sprintf_s(fileName, idLen + 4, "%s.js", id);
|
||||||
if (dataLen > 0) { duk_push_lstring(ctx, retVal, dataLen); free(retVal); }
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
duk_push_string(ctx, retVal);
|
sprintf_s(fileName, idLen + 5 + mpathLen, "%s/%s.js", mpath, id);
|
||||||
|
}
|
||||||
|
int dataLen = ILibReadFileFromDiskEx(&retVal, fileName);
|
||||||
|
if (dataLen > 0)
|
||||||
|
{
|
||||||
|
duk_push_lstring(ctx, retVal, dataLen); free(retVal);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retVal = ILibHashtable_Get(table, ILibDuktape_ModSearch_ModuleFile, id, idLen);
|
||||||
|
if (retVal == NULL)
|
||||||
|
{
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
duk_push_string(ctx, retVal);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return(1);
|
|
||||||
}
|
}
|
||||||
void ILibDuktape_ModSearch_AddModuleObject(duk_context *ctx, char *id, void *heapptr)
|
void ILibDuktape_ModSearch_AddModuleObject(duk_context *ctx, char *id, void *heapptr)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user