The OpenComputers Lua Assembler library (Assembler
) provides a dynamic framework for executing commands with varying numbers of arguments within the OpenComputers mod environment. This module facilitates managing values, sectors, and hardware components programmatically.
- Values Management: Create, move, and manipulate values within the Lua environment.
- Sector Operations: Assign and retrieve values from predefined sectors (
ax
,ex
,as
,es
). - Arithmetic Operations: Perform addition and subtraction operations between values.
- Component Integration: Initialize and interact with hardware components using predefined functions.
- Dynamic Function Execution: Execute functions with a variable number of arguments.
To use the Assembler library in your OpenComputers project, follow these steps:
-
Download: Clone the repository into your OpenComputers project directory:
wget https://raw.githubusercontent.com/DanXvoIsMe/VAsm/main/vasm-lib.lua
-
Include: Import the
Assembler.lua
module in your Lua script:local VAsm = require("vasm-lib")
Here is an example demonstrating how to use the Assembler library:
local VAsm = require("vasm-lib")
local code = """
createvalue myVal 10
move myVal anotherVal
add myVal 5 resultVal
runsectors
"""
VAsm.RunCodeWithoutSandbox(code)
Each command in the code should follow this format:
functionName arg1 arg2 ...
functionName
: The name of the function to execute.arg1
, `arg2```, ...: Arguments passed to the function.
- createvalue(valName, valValue): Creates a new value with the specified name and initial value.
- move(oldvalName, newvalName): Moves a value from
oldvalName
tonewvalName
. - movetosector(sectorName, val): Moves a value to a specified sector (
ax
,ex
,as
,es
). - getfromsector(sectorname, valuename): Retrieves a value from a specified sector.
- add(valuename, addtovalue, outvaluename): Adds
addtovalue
tovaluename
and stores the result inoutvaluename
. - minus(valuename, minusfromvalue, outvaluename): Subtracts
minusfromvalue
fromvaluename
and stores the result inoutvaluename
. - runsectors(): Executes operations related to sectors.
- initcomponent(compoentnname): Initializes a component by its name for future use.
- componentfunction1arg(componentval, arg1): Calls a function on a component with one argument.
- componentfunction2arg(componentval, arg1, arg2): Calls a function on a component with two arguments.
- deintcomponent(compoentnname): Removes a component from the system.
- Functions handle errors gracefully, providing informative messages about incorrect arguments, missing functions, and invalid code formats.
Contributions are welcome! Fork the repository and submit pull requests for any enhancements or bug fixes.
This project is licensed under the MIT License - see the LICENSE file for details.