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

Function PiuLocalsCreate

modules/piu/All/piuLocals.c:50–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48};
49
50void PiuLocalsCreate(xsMachine* the)
51{
52 xsIntegerValue c = xsToInteger(xsArgc);
53 PiuLocals* self;
54 char path[mxLocalsNameSize + 1 + mxLocalsLanguageSize + 4 + 1];
55 size_t size;
56 xsSetHostChunk(xsThis, NULL, sizeof(PiuLocalsRecord));
57 self = PIU(Locals, xsThis);
58 (*self)->reference = xsToReference(xsThis);
59 xsSetHostHooks(xsThis, &PiuLocalsHooks);
60 if ((c > 0) && xsTest(xsArg(0))) {
61 xsStringValue string = xsToString(xsArg(0));
62 if (c_strlen(string) > mxLocalsNameSize - 1)
63 xsRangeError("locals name too long: %s", string);
64 c_strcpy((*self)->name, string);
65 }
66 else
67 c_strcpy((*self)->name, "locals");
68 if ((c > 1) && xsTest(xsArg(1))) {
69 xsStringValue string = xsToString(xsArg(0));
70 if (c_strlen(string) > mxLocalsLanguageSize - 1)
71 xsRangeError("locals language too long: %s", string);
72 c_strcpy((*self)->language, string);
73 }
74 else
75 c_strcpy((*self)->language, "en");
76 c_strcpy(path, (*self)->name);
77 c_strcat(path, ".mhi");
78 (*self)->seeds = (int32_t *)fxGetResource(the, NULL, path, &size);
79 if (!(*self)->seeds) {
80 xsURIError("locals name not found: %s", path);
81 }
82 c_strcpy(path, (*self)->name);
83 c_strcat(path, ".");
84 c_strcat(path, (*self)->language);
85 c_strcat(path, ".mhr");
86 (*self)->results = (int32_t *)fxGetResource(the, NULL, path, &size);
87 if (!(*self)->results) {
88 xsURIError("locals language not found: %s", path);
89 }
90 (*self)->length = c_read32((*self)->seeds);
91}
92
93void PiuLocalsDelete(void* it)
94{

Callers

nothing calls this directly

Calls 1

fxGetResourceFunction · 0.85

Tested by

no test coverage detected