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

Function Install

libaegisub/lua/script_reader.cpp:122–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120 }
121
122 bool Install(lua_State *L, std::vector<fs::path> const& include_path) {
123 // set the module load path to include_path
124 lua_getglobal(L, "package");
125 push_value(L, "path");
126
127 push_value(L, "");
128 for (auto const& path : include_path) {
129 lua_pushfstring(L, "%s/?.lua;%s/?/init.lua;", path.string().c_str(), path.string().c_str());
130 lua_concat(L, 2);
131 }
132
133#ifndef _WIN32
134 // No point in checking any of the default locations on Windows since
135 // there won't be anything there
136 push_value(L, "path");
137 lua_gettable(L, -4);
138 lua_concat(L, 2);
139#endif
140
141 lua_settable(L, -3);
142
143 // Replace the default lua module loader with our unicode compatible one
144 lua_getfield(L, -1, "loaders");
145 push_value(L, exception_wrapper<module_loader>);
146 lua_rawseti(L, -2, 2);
147 lua_pop(L, 2); // loaders, package
148
149#ifdef _WIN32
150 // Replace the default lua IO functions with our unicode compatibile ones
151 luaL_loadstring(L, "require('unicode-monkeypatch')");
152 if (lua_pcall(L, 0, 0, 0)) {
153 return false; // leave error message
154 }
155#endif
156
157 luaL_loadstring(L, "return require('moonscript').loadstring");
158 if (lua_pcall(L, 0, 1, 0)) {
159 return false; // leave error message
160 }
161 lua_setfield(L, LUA_REGISTRYINDEX, "moonscript");
162
163 return true;
164 }
165}

Callers 2

mainFunction · 0.85
CreateMethod · 0.85

Calls 2

push_valueFunction · 0.85
stringMethod · 0.80

Tested by 1

mainFunction · 0.68