MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxLoadModule

Function fxLoadModule

xs/tools/xst.c:1107–1144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1105}
1106
1107void fxLoadModule(txMachine* the, txSlot* module, txID moduleID)
1108{
1109 char path[C_PATH_MAX];
1110 char real[C_PATH_MAX];
1111 txString dot;
1112 txScript* script;
1113#ifdef mxDebug
1114 txUnsigned flags = mxDebugFlag;
1115#else
1116 txUnsigned flags = 0;
1117#endif
1118 if (fxBundleLoad(the, module, moduleID))
1119 return;
1120 c_strncpy(path, fxGetKeyName(the, moduleID), C_PATH_MAX - 1);
1121 path[C_PATH_MAX - 1] = 0;
1122 if (c_realpath(path, real)) {
1123#if mxWindows
1124 DWORD attributes;
1125 attributes = GetFileAttributes(path);
1126 if (attributes != 0xFFFFFFFF) {
1127 if (attributes & FILE_ATTRIBUTE_DIRECTORY)
1128 return;
1129 }
1130#else
1131 struct stat a_stat;
1132 if (stat(path, &a_stat) == 0) {
1133 if (S_ISDIR(a_stat.st_mode))
1134 return;
1135 }
1136#endif
1137 dot = c_strrchr(real, '.');
1138 if (dot && !c_strcmp(dot, ".json"))
1139 flags |= mxJSONModuleFlag;
1140 script = fxLoadScript(the, real, flags);
1141 if (script)
1142 fxResolveModule(the, module, moduleID, script, C_NULL, C_NULL);
1143 }
1144}
1145
1146txScript* fxLoadScript(txMachine* the, txString path, txUnsigned flags)
1147{

Callers

nothing calls this directly

Calls 6

fxBundleLoadFunction · 0.85
fxGetKeyNameFunction · 0.85
c_realpathFunction · 0.85
fxResolveModuleFunction · 0.85
statClass · 0.70
fxLoadScriptFunction · 0.70

Tested by

no test coverage detected