Attach package from string
Adds code from a string as a package with the specified name
- Parameters
- Advanced call ?
Function AttachPackageFromString(Val Lua, Val PackageName, Val Code) 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 |
| Code | - | String | ✔ | Package code |
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
Lua = OPI_Lua.CreateVM("Lua54");
OPI_Lua.AttachPackageFromString(Lua, "calc", "local M = {} function M.double(x) return x * 2 end return M");
OPI_Lua.ExecuteCodeFromString(Lua, "calc = require('calc')");
Parameters = New Array;
Parameters.Add(5);
Result = OPI_Lua.CallFunction(Lua, "calc.double", Parameters);
Result
10