Skip to content

Commit

Permalink
Updated documentation for Lua bindings (cf. #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Oct 18, 2023
1 parent 9f1dd23 commit c2499e3
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 6 deletions.
10 changes: 8 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
- [x] get-card
- [x] get-card-by-index
- [x] put-card
- [x] allow time profile IDs
- [x] delete-card
- [x] delete-all-cards
- [x] get-event
Expand All @@ -50,11 +49,18 @@
- [x] listen
- [x] github workflow + build status
- [x] stylua
- [ ] documentation
- [x] documentation
- [x] dist
- [x] CHANGELOG
- [x] README
- [ ] listen:interrupt
- https://www.lua.org/pil/9.4.html
- https://stackoverflow.com/questions/12889361/lua-sockets-asynchronous-events
- https://jariou.gitbooks.io/comprehensive-lua/content/calling_c_modules_from_lua/networking_with_coroutines_example_using_luasocket.html
- https://stackoverflow.com/questions/13219570/lualanes-and-luasockets
- https://lunarmodules.github.io/copas/reference.html
- https://lua-users.org/wiki/CoroutinesAsConnectionHandlers
- https://github.com/cosock/cosock
- https://stackoverflow.com/questions/50506099/why-is-lua-not-respecting-my-sigint-signal
- https://stackoverflow.com/questions/19145551/lua-socket-cannot-be-properly-stopped-by-ctrlc
- https://www.lua.org/pil/9.4.html
Expand Down
22 changes: 22 additions & 0 deletions bindings/.models/javascript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"javascript": {
"types": {
"uint8": "uint8",
"uint16": "uint16",
"uint32": "uint32",
"bool": "bool",
"IPv4": "netip.Addr",
"MAC": "string",
"version": "string",
"date": "Date",
"shortdate": "Date",
"time": "Time",
"datetime": "DateTime",
"HHmm": "HHmm",
"pin": "PIN",

"optional date": "Date",
"optional datetime": "DateTime"
}
}
}
2 changes: 1 addition & 1 deletion bindings/http/.templates/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{{define "params"}}{{ range $index, $param := .}}{{if ne .type "magic"}}{{if $index}}, {{end}}{{camelCase .name}}{{end}}{{end}}{{end}}

{{define "type"}}{{lookup "go.types" . "???"}}{{end}}
{{define "type"}}{{lookup "javascript.types" . "???"}}{{end}}



133 changes: 130 additions & 3 deletions documentation/CODEGEN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ controller interface in:
- [Zig](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/zig)
- [PHP](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/php)
- [Javascript](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/javascript)
- [Erlang](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/erlang)
- [Lua](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/lua)

The models are provided as JSON files so it's entirely possible to use an alternative templating engine. However, assuming
you've decided on using _uhppoted-codegen_, the remainder of this document outlines the process of creating a language
Expand Down Expand Up @@ -110,9 +112,14 @@ include:
- [test-data.json](https://github.com/uhppoted/uhppoted-codegen/blob/main/bindings/.models/test-data.json)

as well as language specific support for:
- [Go](https://github.com/uhppoted/uhppoted-codegen/blob/main/bindings/.models/go.json)
- [Rust](https://github.com/uhppoted/uhppoted-codegen/blob/main/bindings/.models/rust.json)
- [Python](https://github.com/uhppoted/uhppoted-codegen/blob/main/bindings/.models/python.json)
- [Go](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/go)
- [Rust](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/rust)
- [Python](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/python)
- [Zig](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/zig)
- [PHP](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/php)
- [Javascript](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/javascript)
- [Erlang](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/erlang)
- [Lua](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/lua)

#### [_models.json_](https://github.com/uhppoted/uhppoted-codegen/blob/main/bindings/.models/models.json)

Expand Down Expand Up @@ -290,6 +297,126 @@ The _Python_ types are used in the _Python_ bindings common [templates](https://
{{define "type"}}{{lookup "python.types" . "???"}}{{end}}
```

#### [_zig.json_](https://github.com/uhppoted/uhppoted-codegen/blob/main/bindings/.models/zig.json)

The _zig.json_ models include any _Zig_ specific information - specifically the type conversions from the _models_ types to
valid _Zig_ types:
```
{
"zig": {
"types": {
"uint8": "u8",
"uint16": "u16",
"uint32": "u32",
"bool": "bool",
"IPv4": "network.Address.IPv4",
"MAC": "[6]u8",
...
}
}
}```
The _Zig_ types are used in the _Zig_ bindings common [templates](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/zig/.templates):
```
{{define "type"}}{{lookup "zig.types" . "???"}}{{end}}
```
#### [_php.json_](https://github.com/uhppoted/uhppoted-codegen/blob/main/bindings/.models/php.json)
The _php.json_ models include any _PHP_ specific information - specifically the type conversions from the _models_ types to
valid _PHP_ types:
```
{
"php": {
"types": {
"uint8": "int",
"uint16": "int",
"uint32": "int",
"bool": "bool",
"IPv4": "IPv4Address",
"MAC": "str",
...
}
}
}```

The _PHP_ types are used in the _PHP_ bindings common [templates](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/php/.templates):
```
{{define "type"}}{{lookup "php.types" . "???"}}{{end}}
```

#### [_javascript.json_](https://github.com/uhppoted/uhppoted-codegen/blob/main/bindings/.models/javascript.json)

The _javascript.json_ models include any _Javascript_ specific information - specifically the type conversions from the _models_ types to
valid _Javascript_ types.
```
{
"javascript": {
"types": {
"uint8": "uint8",
"uint16": "uint16",
"uint32": "uint32",
"bool": "bool",
"IPv4": "netip.Addr",
"MAC": "string",
...
}
}
}```
The _Javascript_ types are used in the _Javascript_ bindings common [templates](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/javascript/.templates):
```
{{define "type"}}{{lookup "javascript.types" . "???"}}{{end}}
```
#### [_erlang.json_](https://github.com/uhppoted/uhppoted-codegen/blob/main/bindings/.models/erlang.json)
The _erlang.json_ models include any _Erlang_ specific information - specifically the type conversions from the _models_ types to
valid _Erlang_ types.
```
{
"erlang": {
"types": {
"uint8": "uint8",
"uint16": "uint16",
"uint32": "uint32",
"bool": "bool",
"IPv4": "address",
"MAC": "string",
...
}
}
}```

The _Erlang_ types are used in the _Erlang_ bindings common [templates](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/erlang/.templates):
```
{{define "type"}}{{lookup "erlang.types" . "???"}}{{end}}
```

#### [_lua.json_](https://github.com/uhppoted/uhppoted-codegen/blob/main/bindings/.models/lua.json)

The _lua.json_ models include any _Lua_ specific information - specifically the type conversions from the _models_ types to
valid _Lua_ types.
```
{
"lua": {
"types": {
"uint8": "uint8",
"uint16": "uint16",
"uint32": "uint32",
"bool": "bool",
"IPv4": "address",
"MAC": "string",
...
}
}
}```
The _Lua_ types are used in the _Lua_ bindings common [templates](https://github.com/uhppoted/uhppoted-codegen/tree/main/bindings/lua/.templates):
```
{{define "type"}}{{lookup "erlang.types" . "???"}}{{end}}
```
### Interface structure
The suggested structure for a language binding comprises the following components:
Expand Down

0 comments on commit c2499e3

Please sign in to comment.