xurfer/api.md

94 lines
2.2 KiB
Markdown
Raw Normal View History

## API Reference
2026-06-08 15:54:48 +02:00
<pre>
<a href="">api</a>
2026-06-12 10:02:39 +02:00
<a href="src/lib/json.lua">api.parser.json</a>
<a href="#api-parser-xml">api.parser.xml</a>
2026-06-12 10:02:39 +02:00
<a href="src/lib/url.lua">api.url</a>
<a href="src/util.lua">api.util</a>
<a href="">api.protocol</a>
2026-06-12 10:03:07 +02:00
<a href="#api-ext">api.ext.*</a>
<a href="#api-ext-exec">api.ext.exec(fn, ,..)</a>
2026-06-12 10:02:39 +02:00
<a href="#entity-component-system-ecs">api.ecs</a>
<a href="#entity-component-system-ecs">api.world</a>
</pre>
## Entity Component System (ECS)
Read the Full Documentation here <a href="https://bakpakin.github.io/tiny-ecs/doc">https://bakpakin.github.io/tiny-ecs/doc</a>
> Below are some helper functions to make things more efficient
---
**commit()**
```lua
obj = { foo = "bar", mycomponent = { a = 1 } }
api.ecs.add( api.world, obj )
obj.foo = "flop"
obj.commit('Xhappened')
-- commit notifies all systems to rebuild entitycache
-- because normally systems filter on an entitycache (=fast)
-- which would still rely on foo = "bar".
-- Only do this when you actually need a system to pick
-- up on a change.
```
> also <a href="#api-ext-exec">api.ext.exec('Xhappened')</a> is called so extensions can respond to the change.
2026-06-08 15:54:48 +02:00
## api.parser.xml
2026-06-08 15:56:55 +02:00
```lua
2026-06-08 15:54:48 +02:00
local xml = api.parser.xml.newParser()
2026-06-08 15:56:55 +02:00
local testXml = [[
<testOne param="param1value">
<testTwo paramTwo="param2value">
<testThree>
testThreeValue
</testThree>
<testThree duplicate="one" duplicate="two">
testThreeValueTwo
</testThree>
<test_Four something="else">
testFourValue
</test_Four>
<testFive>
<testFiveDeep>
<testFiveEvenDeeper>
<testSix someParam="someValue"/>
</testFiveEvenDeeper>
</testFiveDeep>
</testFive>
testTwoValue
</testTwo>
</testOne>
]]
2026-06-08 15:54:48 +02:00
util.traverseXML( xml:ParseXmlText(testXml), function(node,raw)
print_r(node)
-- {
-- tag = "div",
-- prop = {
-- style = "color:red; display:none"
-- }
-- }
end)
```
2026-06-12 10:02:39 +02:00
## api.ext.*
This is where extensions live.
See the [skeleton extension](src/ext/skeleton/main.lua) for a typical extension startingpoint.
## api.ext.exec
This allows batch-firing a function on each extension (if exist)
```lua
api.ext.exec('init', 123, "foo") -- call .init(123,"foo") on each extension
```