MCPcopy Index your code
hub / github.com/TypeScriptToLua/TypeScriptToLua / loadImportedLualibFeatures

Function loadImportedLualibFeatures

src/LuaLib.ts:229–258  ·  view source on GitHub ↗
(
    features: Iterable<LuaLibFeature>,
    luaTarget: LuaTarget,
    emitHost: EmitHost
)

Source from the content-addressed store, hash-verified

227}
228
229export function loadImportedLualibFeatures(
230 features: Iterable<LuaLibFeature>,
231 luaTarget: LuaTarget,
232 emitHost: EmitHost
233): lua.Statement[] {
234 const luaLibModuleInfo = getLuaLibModulesInfo(luaTarget, emitHost);
235
236 const imports = Array.from(features).flatMap(feature => luaLibModuleInfo[feature].exports);
237 if (imports.length === 0) {
238 return [];
239 }
240
241 const requireCall = lua.createCallExpression(lua.createIdentifier("require"), [
242 lua.createStringLiteral("lualib_bundle"),
243 ]);
244
245 const luaLibId = lua.createIdentifier("____lualib");
246 const importStatement = lua.createVariableDeclarationStatement(luaLibId, requireCall);
247 const statements: lua.Statement[] = [importStatement];
248 // local <export> = ____luaLib.<export>
249 for (const item of imports) {
250 statements.push(
251 lua.createVariableDeclarationStatement(
252 lua.createIdentifier(item),
253 lua.createTableIndexExpression(luaLibId, lua.createStringLiteral(item))
254 )
255 );
256 }
257 return statements;
258}
259
260const luaLibBundleContent = new Map<string, string>();
261

Callers 1

printFileMethod · 0.90

Calls 1

getLuaLibModulesInfoFunction · 0.85

Tested by

no test coverage detected