Files
Basalt/docs/objects/Program.md
Robert Jelic bb1b1beb79 Basalt 1.7 Update
- New Objects (Flexbox, Graph, Treeview)
- Pluginsystem to add/remove functionality
- Reworked the entire Object system, instead of one big Object Class we have multiple classes: Object, VisualObject, ChangeableObject
- Instead of one big Frame Class we have multiple Frame Classes: BaseFrame, Frame, MovableFrame, ScrollableFrame, MonitorFrame, Flexbox
- Removed the Animation Object, and added a animation plugin instead
- Removed the Graphic Object and merged it's functionality with the image object
- Updated currently existing objects
2023-04-30 17:05:34 +02:00

46 lines
1.8 KiB
Markdown

Program objects allow you to execute other programs within your main application. You can run programs such as worms, shell, or any custom programs you've created. This object also has two unique events: onError and onDone.
In addition to the Object and VisualObject methods, lists also have the following methods:
| | |
|---|---|
|[getStatus](objects/Program/getStatus.md)|Returns the current program status
|[execute](objects/Program/execute.md)|Executes a program
|[stop](objects/Program/stop.md)|Stops the currently running program
|[pause](objects/Program/pause.md)|Pauses the currently running program
|[isPaused](objects/Program/isPaused.md)|Returns if the program is paused
|[injectEvent](objects/Program/injectEvent.md)|Injects an event into the program
|[injectEvents](objects/Program/injectEvents.md)|Injects a table of events
|[getQueuedEvents](objects/Program/getQueuedEvents.md)|Returns currently queued events
|[setEnviroment](objects/Program/setEnviroment.md)|Changes the default environment to a custom one
## Events
This is a list of all available events for programs:
| | |
|---|---|
|[onError](objects/Program/onError.md)|Fires when a program encounters an error
|[onDone](objects/Program/onDone.md)|Fires when a program has finished executing
Here's an example of how to create a Program object, execute a program, and handle events:
Lua:
```lua
local mainFrame = basalt.createFrame()
local aProgram = mainFrame:addProgram()
aProgram:onError(function(self, event, err)
basalt.log("An error occurred: " .. err)
end)
aProgram:onDone(function()
basalt.debug("Program finished successfully")
end)
aProgram:execute("path/to/your/program.lua")
```
This example demonstrates how to create a Program object, execute a program located at "path/to/your/program", and handle the onError and onDone events.