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
This commit is contained in:
@@ -1,19 +1,52 @@
|
||||
## execute
|
||||
|
||||
### Description
|
||||
|
||||
Executes the given path or program
|
||||
|
||||
#### Parameters:
|
||||
1. `string|function` the path to your file as string, or function which should be called
|
||||
### Parameters
|
||||
|
||||
1. `string|function` The path to your file as a string, or a function that should be called
|
||||
|
||||
### Returns
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Executes worm
|
||||
### Usage
|
||||
|
||||
* Execute a custom program:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram()
|
||||
aProgram:execute("rom/programs/fun/worm.lua") -- executes worm
|
||||
|
||||
function customProgram()
|
||||
while true do
|
||||
print("This is a custom program!")
|
||||
sleep(1)
|
||||
end
|
||||
end
|
||||
|
||||
aProgram:execute(customProgram) -- Executes the custom program
|
||||
```
|
||||
|
||||
In this example, a Program object is created and added to the mainFrame. The execute method is then used to execute a custom function called customProgram. The custom program simply prints a debug message to the console.
|
||||
|
||||
* Executing worms:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram()
|
||||
|
||||
aProgram:execute("rom/programs/fun/worm.lua") -- Executes the custom program
|
||||
```
|
||||
|
||||
* Xml version of worms:
|
||||
|
||||
```xml
|
||||
<program path="rom/programs/fun/worm.lua" execute="true" />
|
||||
```
|
||||
|
||||
@@ -1,34 +1,27 @@
|
||||
## getQueuedEvents
|
||||
If the program is paused, incomming events will be inserted into a queued events table. As soon as the program is unpaused, the queued events table will be empty
|
||||
|
||||
#### Returns:
|
||||
1. `table` a table - {event="event", args={"a", "b",...}}
|
||||
### Description
|
||||
|
||||
#### Usage:
|
||||
* prints the queued events table
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame():show()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
|
||||
mainFrame:addButton():setText("inject"):onClick(function() basalt.debug(aProgram:getQueuedEvents()) end):show()
|
||||
```
|
||||
If the program is paused, incoming events will be inserted into a queued events table. As soon as the program is unpaused, the queued events table will be empty.
|
||||
|
||||
## updateQueuedEvents
|
||||
Here you can manipulate the queued events table
|
||||
### Returns
|
||||
|
||||
#### Parameters:
|
||||
1. `table` a table, items should be {event="event", args={para1, para2, para3, para4}}
|
||||
1. `table` A table with queued events: {event="event", args={"a", "b",...}}
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
### Usage
|
||||
|
||||
* Print the queued events table:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame():show()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
|
||||
local basalt = require("basalt")
|
||||
|
||||
mainFrame:addButton():setText("inject"):onClick(function()
|
||||
local events = aProgram:getQueuedEvents()
|
||||
table.insert(events,1,{event="char", args={"w"}}
|
||||
aProgram:updateQueuedEvents(events)
|
||||
end):show()
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua")
|
||||
|
||||
local function printQueuedEvents()
|
||||
local queuedEvents = aProgram:getQueuedEvents()
|
||||
basalt.debug(queuedEvents)
|
||||
end
|
||||
|
||||
mainFrame:addButton():setText("Show Queued Events"):onClick(printQueuedEvents)
|
||||
```
|
||||
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
## getStatus
|
||||
returns the current process status
|
||||
|
||||
#### Returns:
|
||||
1. `string` current status ("running", "normal, "suspended", or "dead")
|
||||
### Description
|
||||
|
||||
Returns the current process status.
|
||||
|
||||
### Returns
|
||||
|
||||
1. `string` The current status ("running", "normal", "suspended", or "dead")
|
||||
|
||||
### Usage
|
||||
|
||||
* Print the current status:
|
||||
|
||||
#### Usage:
|
||||
* Prints current status
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram()
|
||||
basalt.debug(aProgram:getStatus())
|
||||
```
|
||||
|
||||
local status = aProgram:getStatus()
|
||||
basalt.debug("The current status of the program is:", status)
|
||||
```
|
||||
|
||||
In this example, a Program object is created and added to the mainFrame. The getStatus method is then used to retrieve the current status of the Program, which is printed to the console as a debug message.
|
||||
|
||||
@@ -1,21 +1,36 @@
|
||||
## injectEvent
|
||||
injects a event into the program manually. For example you could inject w a s and d for worm, by clicking buttons.
|
||||
|
||||
#### Parameters:
|
||||
### Description
|
||||
|
||||
Injects an event into the program manually. For example, you could inject "w", "a", "s", and "d" for the worm game by clicking buttons.
|
||||
|
||||
### Parameters
|
||||
|
||||
1. `string` event
|
||||
2. `any` parameter
|
||||
3. `any` parameter
|
||||
4. `any` parameter
|
||||
5. `any` parameter
|
||||
6. `boolean` if this is true, the injected event will be executed even if the program is paused
|
||||
2. `boolean` if this is true, the injected event will be executed even if the program is paused
|
||||
3. `any` ... parameters
|
||||
|
||||
### Returns
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* injects a event by clicking a button
|
||||
### Usage
|
||||
|
||||
* Inject an event by clicking a button
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame():show()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
|
||||
mainFrame:addButton():setText("inject"):onClick(function() aProgram:injectEvent("char", "w") end):show()
|
||||
```
|
||||
local basalt = require("basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua")
|
||||
|
||||
local function injectEventOnClick()
|
||||
aProgram:injectEvent("char", false, "w")
|
||||
end
|
||||
|
||||
mainFrame:addButton()
|
||||
:setText("Inject W")
|
||||
:onClick(injectEventOnClick)
|
||||
```
|
||||
|
||||
In this example, a Program object is created, added to the mainFrame, and the "rom/programs/shell.lua" script is executed. A button is then added to the mainFrame that, when clicked, injects the "char" event with a parameter of "w" into the Program.
|
||||
|
||||
@@ -1,23 +1,35 @@
|
||||
## injectEvents
|
||||
Injects multiple events
|
||||
|
||||
#### Parameters:
|
||||
1. `table` a table, items should be {event="event", args={para1, para2, para3, para4}}
|
||||
### Description
|
||||
|
||||
Injects multiple events into the program.
|
||||
|
||||
### Parameters
|
||||
|
||||
1. `table` ... - A table containing an "event" key and an "args" key. The "event" key should have a string value, and the "args" key should have a table value containing the parameters for the event.
|
||||
|
||||
### Returns
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
### Usage
|
||||
|
||||
* injects a multiple char events by clicking a button
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame():show()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
|
||||
local basalt = require("basalt")
|
||||
|
||||
local events = {
|
||||
{event="char", args={"h"}},
|
||||
{event="char", args={"e"}},
|
||||
{event="char", args={"y"}}
|
||||
}
|
||||
mainFrame:addButton():setText("inject"):onClick(function() aProgram:injectEvents(events) end):show()
|
||||
```
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua")
|
||||
|
||||
local function injectEventsOnClick()
|
||||
aProgram:injectEvents(
|
||||
{event="char", args={"h"}},
|
||||
{event="char", args={"e"}},
|
||||
{event="char", args={"y"}})
|
||||
end
|
||||
|
||||
mainFrame:addButton()
|
||||
:setText("Inject 'hey'")
|
||||
:onClick(injectEventsOnClick)
|
||||
```
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
## isPaused
|
||||
returns if the program is paused
|
||||
|
||||
#### Returns:
|
||||
1. `boolean` pause status
|
||||
### Description
|
||||
|
||||
Returns whether the program is paused or not.
|
||||
|
||||
### Returns
|
||||
|
||||
1. `boolean` The pause status of the program
|
||||
|
||||
### Usage
|
||||
|
||||
* Print the pause status of the program:
|
||||
|
||||
#### Usage:
|
||||
* Prints the pause status of the program
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame():show()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
|
||||
basalt.debug(aProgram:isPaused())
|
||||
```
|
||||
local basalt = require("basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua")
|
||||
local pausedStatus = aProgram:isPaused()
|
||||
|
||||
basalt.debug("Is the program paused?", pausedStatus)
|
||||
```
|
||||
|
||||
In this example, a Program object is created, added to the mainFrame, and the "rom/programs/shell.lua" script is executed. The `isPaused` method is then called to determine whether the program is paused or not, and the result is printed to the console.
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
# onDone
|
||||
## onDone
|
||||
|
||||
### Description
|
||||
|
||||
`onDone(self, err)`
|
||||
|
||||
`onDone(self, err)`<br>
|
||||
This is a custom event which gets triggered as soon as the program has finished.
|
||||
|
||||
Here is a example on how to add a onDone event to your program:
|
||||
### Returns
|
||||
|
||||
1. `object` The object in use
|
||||
|
||||
### Usage
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
@@ -11,9 +18,15 @@ local basalt = require("basalt")
|
||||
local main = basalt.createFrame()
|
||||
local aProgram = main:addProgram():execute("rom/programs/shell.lua")
|
||||
|
||||
local function onProgramDone()
|
||||
basalt.debug("Program has finished")
|
||||
local function onProgramDone(self, err)
|
||||
if err then
|
||||
basalt.debug("Program finished with error:", err)
|
||||
else
|
||||
basalt.debug("Program has finished successfully")
|
||||
end
|
||||
end
|
||||
|
||||
aProgram:onDone(onProgramDone)
|
||||
```
|
||||
|
||||
In this example, a Program object is created, added to the mainFrame, and the "rom/programs/shell.lua" script is executed. The `onDone` event is then attached to the program, and it will be triggered when the program finishes. The event function, `onProgramDone`, will print a debug message indicating whether the program finished successfully or with an error.
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
# onError
|
||||
|
||||
`onError(self, err)`<br>
|
||||
This is a custom event which gets triggered as soon as the program catched a error.
|
||||
### Description
|
||||
|
||||
Here is a example on how to add a onError event to your program:
|
||||
`onError(self, err)`
|
||||
|
||||
This is a custom event which gets triggered as soon as the program catches an error.
|
||||
|
||||
### Returns
|
||||
|
||||
1. `object` The object in use
|
||||
|
||||
### Usage
|
||||
|
||||
* Add an onError event to a program:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
@@ -12,23 +21,25 @@ local main = basalt.createFrame()
|
||||
local aProgram = main:addProgram():execute("rom/programs/shell.lua")
|
||||
|
||||
local function onProgramError(self, err)
|
||||
local errFrame = main:addFrame()
|
||||
:setSize(30, 10)
|
||||
:setPosition("parent.w / 2 - self.w / 2", "parent.h / 2 - self.h / 2")
|
||||
local errFrame = main:addFrame()
|
||||
:setSize(30, 10)
|
||||
:setPosition("parent.w / 2 - self.w / 2", "parent.h / 2 - self.h / 2")
|
||||
|
||||
errFrame:addLabel()
|
||||
:setPosition(2, 3)
|
||||
:setSize("parent.w - 2", "parent.h - 3")
|
||||
:setText(err)
|
||||
errFrame:addLabel()
|
||||
:setPosition(2, 3)
|
||||
:setSize("parent.w - 2", "parent.h - 3")
|
||||
:setText(err)
|
||||
|
||||
errFrame:addButton()
|
||||
:setPosition("parent.w", 1)
|
||||
:setSize(1, 1)
|
||||
:setText("X")
|
||||
:onClick(function()
|
||||
errFrame:remove()
|
||||
end)
|
||||
errFrame:addButton()
|
||||
:setPosition("parent.w", 1)
|
||||
:setSize(1, 1)
|
||||
:setText("X")
|
||||
:onClick(function()
|
||||
errFrame:remove()
|
||||
end)
|
||||
end
|
||||
|
||||
aProgram:onError(onProgramError)
|
||||
```
|
||||
|
||||
In this example, a Program object is created, added to the mainFrame, and the "rom/programs/shell.lua" script is executed. The `onError` event is then attached to the program, and it will be triggered when the program catches an error. The event function, `onProgramError`, will create an error Frame displaying the error message and a button to close the error Frame.
|
||||
|
||||
@@ -1,16 +1,38 @@
|
||||
## pause
|
||||
pauses the current program (prevents the program from receiving events)
|
||||
|
||||
#### Parameters:
|
||||
1. `boolean` true, false or nothing
|
||||
### Description
|
||||
|
||||
Pauses the current program (prevents the program from receiving events)
|
||||
|
||||
### Parameters
|
||||
|
||||
1. `boolean` true, false, or nothing (optional)
|
||||
|
||||
### Returns
|
||||
|
||||
#### Returns:
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Pauses worm by clicking a button
|
||||
### Usage
|
||||
|
||||
* Pause a program by clicking a button:
|
||||
|
||||
```lua
|
||||
local mainFrame = basalt.createFrame():show()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua"):show()
|
||||
mainFrame:addButton():setText("Pause"):onClick(function() aProgram:pause(true) end):show()
|
||||
```
|
||||
local basalt = require("basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua")
|
||||
|
||||
local pauseButton = mainFrame:addButton()
|
||||
:setText("Pause")
|
||||
:onClick(function()
|
||||
if aProgram:isPaused() then
|
||||
aProgram:pause(false)
|
||||
pauseButton:setText("Pause")
|
||||
else
|
||||
aProgram:pause(true)
|
||||
pauseButton:setText("Resume")
|
||||
end
|
||||
end)
|
||||
```
|
||||
|
||||
In this example, a Program object is created, added to the mainFrame, and the "rom/programs/shell.lua" script is executed. A button is then added to the mainFrame, and when clicked, it will toggle the pause state of the program. The button text will change accordingly to indicate whether the program is paused or resumed.
|
||||
|
||||
@@ -1,10 +1,38 @@
|
||||
## setEnviroment
|
||||
Changes the default enviroment to a custom enviroment
|
||||
|
||||
#### Parameters:
|
||||
### Description
|
||||
|
||||
Changes the default environment to a custom environment
|
||||
|
||||
### Parameters
|
||||
|
||||
1. `table` - Enviroment table
|
||||
|
||||
#### Returns:
|
||||
### Returns
|
||||
|
||||
1. `program` Program in use
|
||||
1. `object` object in use
|
||||
|
||||
### Usage
|
||||
|
||||
* Set a custom environment for a program:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram()
|
||||
|
||||
local customEnvironment = {
|
||||
print = function(...)
|
||||
local args = {...}
|
||||
basalt.debug("Custom print:", unpack(args))
|
||||
end
|
||||
}
|
||||
|
||||
aProgram:setEnvironment(customEnvironment) -- Set the custom environment
|
||||
aProgram:execute(function()
|
||||
print("Hello, World!")
|
||||
end)
|
||||
```
|
||||
|
||||
In this example, a Program object is created and added to the mainFrame. A custom environment table is created with a custom `print` function. The custom environment is then set for the program using the `setEnvironment` method. When the program is executed, it will use the custom `print` function from the custom environment instead of the default print function.
|
||||
|
||||
@@ -1,14 +1,34 @@
|
||||
## stop
|
||||
|
||||
### Description
|
||||
|
||||
Stops a currently running program
|
||||
|
||||
#### Returns:
|
||||
### Returns
|
||||
|
||||
1. `object` The object in use
|
||||
|
||||
#### Usage:
|
||||
* Stops worm by clicking a button
|
||||
### Usage
|
||||
|
||||
* Stops a running program by clicking a button:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram()
|
||||
aProgram:execute("rom/programs/fun/worm.lua") -- executes worm
|
||||
mainFrame:addButton():setText("Pause"):onClick(function() aProgram:stop() end):show()
|
||||
```
|
||||
|
||||
aProgram:execute("rom/programs/fun/worm.lua") -- Executes the worm program
|
||||
|
||||
local stopButton = mainFrame:addButton()
|
||||
:setText("Stop")
|
||||
:setPosition(5, 5)
|
||||
:setSize(10, 3)
|
||||
:onClick(function()
|
||||
aProgram:stop() -- Stop the program when the button is clicked
|
||||
end)
|
||||
|
||||
basalt.autoUpdate()
|
||||
```
|
||||
|
||||
In this example, a Program object is created and added to the mainFrame. The worm program is executed using the `execute` method. A button with the text "Stop" is added to the mainFrame, and when clicked, it will stop the running worm program using the `stop` method.
|
||||
|
||||
34
docs/objects/Program/updateQueuedEvents.md
Normal file
34
docs/objects/Program/updateQueuedEvents.md
Normal file
@@ -0,0 +1,34 @@
|
||||
## updateQueuedEvents
|
||||
|
||||
### Description
|
||||
|
||||
Manipulate the queued events table.
|
||||
|
||||
### Parameters
|
||||
|
||||
1. `table` A table with queued events: {event="event", args={"a", "b",...}}
|
||||
|
||||
### Returns
|
||||
|
||||
1. `object` The object in use
|
||||
|
||||
### Usage
|
||||
|
||||
* Update the queued events table:
|
||||
|
||||
```lua
|
||||
local basalt = require("basalt")
|
||||
|
||||
local mainFrame = basalt.createFrame()
|
||||
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua")
|
||||
|
||||
local function updateQueuedEvents()
|
||||
local events = aProgram:getQueuedEvents()
|
||||
table.insert(events, 1, {event="char", args={"w"}})
|
||||
aProgram:updateQueuedEvents(events)
|
||||
end
|
||||
|
||||
mainFrame:addButton():setText("Update Queued Events"):onClick(updateQueuedEvents)
|
||||
```
|
||||
|
||||
In this example, a button is created to update the queued events table of a Program. When the button is clicked, the updateQueuedEvents function is executed, which retrieves the current queued events, inserts a new event, and then updates the queued events table in the Program object.
|
||||
Reference in New Issue
Block a user