Attach package from file
Adds code from a file as a package with the specified name
- Parameters
- Advanced call ?
Function AttachPackageFromFile(Val Lua, Val PackageName, Val Path) Export
| Parameter | CLI option | Type | Required | Description |
|---|---|---|---|---|
| Lua | - | Arbitrary | ✔ | Lua AddIn or Lua version to run |
| PackageName | - | String | ✔ | The name of the package by which it will be available after adding |
| Path | - | String | ✔ | Path to code file |
Returns
Map Of KeyAndValue - Add result
| Parameter | Description |
|---|---|
| addin_mode | Manual selection of external component connection mode (for 1C): Isolated, NotIsolated |
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