MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / loadModule

Function loadModule

pj_scripting/src/luau_engine.cpp:333–362  ·  view source on GitHub ↗

Compile + load `source` and run its main chunk, leaving the returned module value on top of `L`. Returns an error string (empty on success).

Source from the content-addressed store, hash-verified

331// Compile + load `source` and run its main chunk, leaving the returned module
332// value on top of `L`. Returns an error string (empty on success).
333std::string loadModule(lua_State* L, BudgetState* budget, const std::string& source) {
334 if (source.size() > kMaxSourceBytes) { // luau_compile runs on the host heap, outside the VM cap
335 return "filter source exceeds the size limit";
336 }
337 lua_CompileOptions opts = {};
338 opts.optimizationLevel = 1;
339 opts.debugLevel = 1; // line info for error messages
340 std::size_t bc_size = 0;
341 char* bc = luau_compile(source.c_str(), source.size(), &opts, &bc_size);
342 if (bc == nullptr) {
343 return "luau_compile failed";
344 }
345 const int load_status = luau_load(L, "=filter", bc, bc_size, 0);
346 std::free(bc);
347 if (load_status != 0) {
348 std::string err = lua_isstring(L, -1) ? lua_tostring(L, -1) : "luau_load failed";
349 lua_pop(L, 1);
350 return err;
351 }
352 if (lua_pcall(L, 0, 1, 0) != 0) {
353 std::string err = lua_isstring(L, -1) ? lua_tostring(L, -1) : "module evaluation failed";
354 lua_pop(L, 1);
355 return err;
356 }
357 if (budget->tripped) { // a top-level pcall may have swallowed the watchdog error
358 lua_pop(L, 1);
359 return "filter module exceeded its instruction budget during evaluation";
360 }
361 return {};
362}
363
364// Read metadata (NOT create) from the class table on top of `L` into a
365// FilterClass. Leaves the stack as found. Returns an error string.

Callers 2

inspectModuleMethod · 0.85
createInstanceMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected