MCPcopy Create free account
hub / github.com/TypesettingTools/Aegisub / Create

Method Create

src/auto4_lua.cpp:418–536  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

416 }
417
418 void LuaScript::Create()
419 {
420 Destroy();
421
422 name = GetPrettyFilename().string();
423
424 // create lua environment
425 L = luaL_newstate();
426 if (!L) {
427 description = "Could not initialize Lua state";
428 return;
429 }
430
431 bool loaded = false;
432 BOOST_SCOPE_EXIT_ALL(&) { if (!loaded) Destroy(); };
433 LuaStackcheck stackcheck(L);
434
435 // register standard libs
436 preload_modules(L);
437 stackcheck.check_stack(0);
438
439 // dofile and loadfile are replaced with include
440 lua_pushnil(L);
441 lua_setglobal(L, "dofile");
442 lua_pushnil(L);
443 lua_setglobal(L, "loadfile");
444 push_value(L, exception_wrapper<LuaInclude>);
445 lua_setglobal(L, "include");
446
447 // Replace the default lua module loader with our unicode compatible
448 // one and set the module search path
449 if (!Install(L, include_path)) {
450 description = get_string_or_default(L, 1);
451 lua_pop(L, 1);
452 return;
453 }
454 stackcheck.check_stack(0);
455
456 // prepare stuff in the registry
457
458 // store the script's filename
459 push_value(L, GetFilename().stem());
460 lua_setfield(L, LUA_REGISTRYINDEX, "filename");
461 stackcheck.check_stack(0);
462
463 // reference to the script object
464 push_value(L, this);
465 lua_setfield(L, LUA_REGISTRYINDEX, "aegisub");
466 stackcheck.check_stack(0);
467
468 // make "aegisub" table
469 lua_pushstring(L, "aegisub");
470 lua_createtable(L, 0, 13);
471
472 set_field<LuaCommand::LuaRegister>(L, "register_macro");
473 set_field<LuaExportFilter::LuaRegister>(L, "register_filter");
474 set_field<lua_text_textents>(L, "text_extents");
475 set_field<frame_from_ms>(L, "frame_from_ms");

Callers 3

PlayMethod · 0.45
ShowDialogMethod · 0.45
PlayMethod · 0.45

Calls 10

preload_modulesFunction · 0.85
push_valueFunction · 0.85
InstallFunction · 0.85
get_string_or_defaultFunction · 0.85
set_fieldFunction · 0.85
LoadFileFunction · 0.85
get_global_stringFunction · 0.85
stringMethod · 0.80
formatFunction · 0.70
check_stackMethod · 0.45

Tested by

no test coverage detected