Skip to content

Commit 617fa6f

Browse files
author
null0 templates
committed
sync from null0 0.0.16
1 parent 31ed7af commit 617fa6f

18 files changed

Lines changed: 96 additions & 1521 deletions

.github/workflows/publish.yml

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
workflow_dispatch:
77

88
permissions:
9+
contents: read
910
pages: write
1011
id-token: write
1112

@@ -14,23 +15,11 @@ jobs:
1415
runs-on: ubuntu-latest
1516
steps:
1617
- uses: actions/checkout@v4
17-
- name: Install WASI SDK
18-
uses: konsumer/install-wasi-sdk@v1
19-
with:
20-
version: "25"
21-
- name: Install Nelua
22-
run:
23-
|
24-
git clone https://github.com/edubart/nelua-lang.git
25-
cd nelua-lang
26-
make
27-
sudo make install
28-
- name: Configure CMake
29-
run: cmake -B build -DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk.cmake -DCMAKE_BUILD_TYPE=Release
30-
- name: Build CMake
31-
run: cmake --build build
32-
- name: Upload artifact
33-
uses: actions/upload-pages-artifact@v3
18+
- name: Build cart
19+
run: |
20+
mkdir -p webroot
21+
rm -f webroot/mygame.null0 && docker run --rm -v ./cart:/src -v ./webroot:/out ghcr.io/notnullgames/null0-cart-nelua:latest mygame
22+
- uses: actions/upload-pages-artifact@v3
3423
with:
3524
path: ./webroot
3625

.github/workflows/release.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,11 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
15-
- name: Install WASI SDK
16-
uses: konsumer/install-wasi-sdk@v1
17-
with:
18-
version: "25"
19-
- name: Install Nelua
20-
run:
21-
|
22-
git clone https://github.com/edubart/nelua-lang.git
23-
cd nelua-lang
24-
make
25-
sudo make install
26-
- name: Configure CMake
27-
run: cmake -B build -DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk.cmake -DCMAKE_BUILD_TYPE=Release
28-
- name: Build CMake
29-
run: cmake --build build
30-
- run: gh release upload ${{github.event.release.tag_name}} *.null0
15+
- name: Build cart
16+
run: |
17+
mkdir -p webroot
18+
rm -f webroot/mygame.null0 && docker run --rm -v ./cart:/src -v ./webroot:/out ghcr.io/notnullgames/null0-cart-nelua:latest mygame
19+
- name: Attach cart to release
20+
run: gh release upload ${{ github.event.release.tag_name }} webroot/mygame.null0
3121
env:
3222
GH_TOKEN: ${{ github.token }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.DS_Store
22
.vscode
3-
build
3+
4+
# the cart is a build artifact
5+
webroot/*.null0

CMakeLists.txt

Lines changed: 0 additions & 29 deletions
This file was deleted.

README.md

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,55 @@
1-
This is a basic example cart in Nelua for the [null0](https://notnull.games/null0) game-engine.
1+
# mygame
22

3-
## usage
3+
A starter [null0](https://notnull.games/null0) cart, in Nelua.
44

5-
Carts run natively, and on the web. This repo will auto-publish to github-pages on push, so users can check out your cart without installing anything.
5+
Press **Use this template** to make your own, then search the project for `mygame` and rename it to whatever your game is called.
66

7-
They can also install [the native runtime](https://github.com/notnullgames/null0/releases) and use it to run your cart.
7+
## building
88

9-
## github
9+
Everything is built inside docker, so you never install nelua + wasi-sdk clang yourself. All you need is [docker](https://docs.docker.com/get-started/get-docker/), plus [node](https://nodejs.org/) for the shortcuts below.
1010

11-
There are 2 actions:
12-
13-
- Publish demo to github-pages - this happens on any push
14-
- Attach current version of your cart to any releases that are created (like [here](https://github.com/notnullgames/cart_nelua/releases/))
15-
16-
## developing
17-
18-
Make sure you have [wasi-sdk](https://github.com/WebAssembly/wasi-sdk/releases) installed and `WASI_SDK_PATH` set to it's location (eg `/opt/wasi-sdk`.)
11+
```sh
12+
npm start
13+
```
1914

20-
Then you can do this:
15+
That builds `webroot/mygame.null0`, serves `webroot/`, and rebuilds whenever you edit something in `cart/`. To build once, without the server:
2116

2217
```sh
23-
nelua --cflags="-I ." -L . "src/main.nelua" -r --cc "$WASI_SDK_PATH/bin/clang" -o src/main.wasm
24-
cd src
25-
zip -r ../webroot/mygame.null0 . -x '*.nelua' '.DS_Store'
18+
npm run build
2619
```
2720

28-
You can also use cmake (recommended) to build a complete cart:
21+
Or call docker yourself:
2922

3023
```sh
31-
cmake -B build -DCMAKE_TOOLCHAIN_FILE="${WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake" -DCMAKE_BUILD_TYPE=Release
32-
cmake --build build
24+
rm -f webroot/mygame.null0
25+
docker run --rm --user $(id -u):$(id -g) -v ./cart:/src -v ./webroot:/out ghcr.io/notnullgames/null0-cart-nelua:latest mygame
3326
```
3427

35-
You will find your cart in `webroot/mygame.null0`
28+
## writing your game
3629

37-
If you have node installed, you can also get a nice watching-webseerver, locally:
30+
Your code is in `cart/main.nelua`. A cart implements the callbacks it cares about and the host skips the rest:
3831

32+
```lua
33+
local function load() <cexport'load'> end
3934
```
40-
npm start
41-
```
4235

43-
After this, create a github-release, and your cart will show up on releases (like [here](https://github.com/notnullgames/cart_nelua/releases/)).
36+
### Nelua notes
37+
38+
- `require 'null0'`. Nelua compiles to C, so it needs null0.h alongside null0.nelua.
39+
40+
You do not need to copy any null0 bindings into this project - the docker image bakes the current [`carts/nelua/null0.nelua`](https://raw.githubusercontent.com/notnullgames/null0/main/carts/nelua/null0.nelua) in for you.
41+
42+
## docs
43+
44+
- [Nelua carts](https://notnull.games/null0/languages/nelua) - the whole API, in Nelua
45+
- [Anatomy of a cart](https://notnull.games/null0/cart) - callbacks, input, distribution
46+
- [API reference](https://notnull.games/null0/api)
47+
48+
## publishing
49+
50+
Two workflows come with this template:
51+
52+
- **Publish** builds the cart and deploys `webroot/` to github-pages on every push to `main`, so anyone can play your game in a browser without installing anything.
53+
- **Release** attaches `mygame.null0` to any github release you create.
4454

55+
Players who want it natively can grab [the runtime](https://github.com/notnullgames/null0/releases) and run `null0 mygame.null0`.

cart/main.nelua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'null0'
2+
3+
local function load() <cexport'load'>
4+
clear(BLUE)
5+
draw_circle(100, 100, 50, RED)
6+
end
7+
8+
-- callbacks (optional - implement as needed)
9+
10+
-- local function update() <cexport'update'> end
11+
-- local function unload() <cexport'unload'> end
12+
-- local function buttonUp(button: GamepadButton, player: uint32) <cexport'buttonUp'> end
13+
-- local function buttonDown(button: GamepadButton, player: uint32) <cexport'buttonDown'> end
14+
-- local function keyUp(key: Key) <cexport'keyUp'> end
15+
-- local function keyDown(key: Key) <cexport'keyDown'> end
16+
-- local function mouseDown(button: MouseButton) <cexport'mouseDown'> end
17+
-- local function mouseUp(button: MouseButton) <cexport'mouseUp'> end
18+
-- local function mouseMoved(x: float32, y: float32) <cexport'mouseMoved'> end

0 commit comments

Comments
 (0)