Skip to main content

Attach package from file

Adds code from a file as a package with the specified name

Function AttachPackageFromFile(Val Lua, Val PackageName, Val Path) Export

ParameterCLI optionTypeRequiredDescription
Lua-ArbitraryLua AddIn or Lua version to run
PackageName-StringThe name of the package by which it will be available after adding
Path-StringPath to code file
Returns

Map Of KeyAndValue - Add result

Caution

NOCLI: this method is not available in CLI version

1C:Enterprise/OneScript code example
PackageFile = GetTempFileName("lua");
GetBinaryDataFromString("local M = {} function M.triple(x) return x * 3 end return M").Write(PackageFile);

Lua = OPI_Lua.CreateVM("Lua54");

OPI_Lua.AttachPackageFromFile(Lua, "calc_file", PackageFile);

OPI_Lua.ExecuteCodeFromString(Lua, "calc_file = require('calc_file')");

Parameters = New Array;
Parameters.Add(4);

Result = OPI_Lua.CallFunction(Lua, "calc_file.triple", Parameters);
Result
12