Skip to content

Commit

Permalink
Contributing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasvlevi committed May 6, 2024
1 parent 1d2bce7 commit ef882ad
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 55 deletions.
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Contributing

Add all the exposed lua bindings in `./src/bindings/*.h`

Include your bindings in `./src/lu5_bindings.c` and register them to the lua state using `LUA_ADD_FUNCTION` macro

Add a documentation comment for each lua binding.

Build the application and the static documentation site.

```
make docs
```

Send a PR!
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,11 @@ lu5 file.lua
![lu5 preview instances](./docs/assets/text_demo.png)

<br>

---

### Contributions

Contributions to expand the lu5 api are welcomed.

Read the [contribution docs](./CONTRIBUTING.md)
Binary file added docs/assets/lu5_thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1 class="module">Reference</h1>
<span class="text version">v0.0.2</span>
</header>

<div class="modules" id="reactive"><div class="summary"><h3>setting</h3><ul><li class="index"><a class="dark index" href="./setting.html#fill">fill</a></li><li class="index"><a class="dark index" href="./setting.html#strokeWeight">strokeWeight</a></li><li class="index"><a class="dark index" href="./setting.html#noFill">noFill</a></li><li class="index"><a class="dark index" href="./setting.html#stroke">stroke</a></li><li class="index"><a class="dark index" href="./setting.html#noStroke">noStroke</a></li><li class="index"><a class="dark index" href="./setting.html#textSize">textSize</a></li><li class="index"><a class="dark index" href="./setting.html#textFont">textFont</a></li></ul></div><div class="summary"><h3>shapes</h3><ul><li class="index"><a class="dark index" href="./shapes.html#circle">circle</a></li><li class="index"><a class="dark index" href="./shapes.html#rect">rect</a></li><li class="index"><a class="dark index" href="./shapes.html#square">square</a></li><li class="index"><a class="dark index" href="./shapes.html#line">line</a></li><li class="index"><a class="dark index" href="./shapes.html#quad">quad</a></li><li class="index"><a class="dark index" href="./shapes.html#text">text</a></li><li class="index"><a class="dark index" href="./shapes.html#point">point</a></li><li class="index"><a class="dark index" href="./shapes.html#arc">arc</a></li><li class="index"><a class="dark index" href="./shapes.html#ellipse">ellipse</a></li><li class="index"><a class="dark index" href="./shapes.html#triangle">triangle</a></li></ul></div><div class="summary"><h3>math</h3><ul><li class="index"><a class="dark index" href="./math.html#round">round</a></li></ul></div><div class="summary"><h3>events</h3><ul><li class="index"><a class="dark index" href="./events.html#isKeyDown">isKeyDown</a></li></ul></div><div class="summary"><h3>window</h3><ul><li class="index"><a class="dark index" href="./window.html#createWindow">createWindow</a></li><li class="index"><a class="dark index" href="./window.html#background">background</a></li></ul></div><div class="summary"><h3>io</h3><ul><li class="index"><a class="dark index" href="./io.html#print">print</a></li></ul></div><div class="summary"><h3>loaders</h3><ul><li class="index"><a class="dark index" href="./loaders.html#loadFont">loadFont</a></li></ul></div></div>
<div class="modules" id="reactive"><div class="summary"><h3>shapes</h3><ul><li class="index"><a class="dark index" href="./shapes.html#circle">circle</a></li><li class="index"><a class="dark index" href="./shapes.html#rect">rect</a></li><li class="index"><a class="dark index" href="./shapes.html#square">square</a></li><li class="index"><a class="dark index" href="./shapes.html#line">line</a></li><li class="index"><a class="dark index" href="./shapes.html#quad">quad</a></li><li class="index"><a class="dark index" href="./shapes.html#text">text</a></li><li class="index"><a class="dark index" href="./shapes.html#point">point</a></li><li class="index"><a class="dark index" href="./shapes.html#arc">arc</a></li><li class="index"><a class="dark index" href="./shapes.html#ellipse">ellipse</a></li><li class="index"><a class="dark index" href="./shapes.html#triangle">triangle</a></li></ul></div><div class="summary"><h3>math</h3><ul><li class="index"><a class="dark index" href="./math.html#round">round</a></li></ul></div><div class="summary"><h3>io</h3><ul><li class="index"><a class="dark index" href="./io.html#print">print</a></li></ul></div><div class="summary"><h3>setting</h3><ul><li class="index"><a class="dark index" href="./setting.html#fill">fill</a></li><li class="index"><a class="dark index" href="./setting.html#strokeWeight">strokeWeight</a></li><li class="index"><a class="dark index" href="./setting.html#noFill">noFill</a></li><li class="index"><a class="dark index" href="./setting.html#stroke">stroke</a></li><li class="index"><a class="dark index" href="./setting.html#noStroke">noStroke</a></li><li class="index"><a class="dark index" href="./setting.html#textSize">textSize</a></li><li class="index"><a class="dark index" href="./setting.html#textFont">textFont</a></li></ul></div><div class="summary"><h3>events</h3><ul><li class="index"><a class="dark index" href="./events.html#isKeyDown">isKeyDown</a></li></ul></div><div class="summary"><h3>window</h3><ul><li class="index"><a class="dark index" href="./window.html#createWindow">createWindow</a></li><li class="index"><a class="dark index" href="./window.html#background">background</a></li></ul></div><div class="summary"><h3>loaders</h3><ul><li class="index"><a class="dark index" href="./loaders.html#loadFont">loadFont</a></li></ul></div></div>
</main>
</body>
</html>
Empty file added examples/CONTRIBUTING.md
Empty file.
108 changes: 54 additions & 54 deletions src/lu5_bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,104 +11,104 @@
#include "lu5_defs.h"

void lu5_update_dynamic_variables(lua_State *L, GLFWwindow *window) {
double mouseX, mouseY;
glfwGetCursorPos(window, &mouseX, &mouseY);
double mouseX, mouseY;
glfwGetCursorPos(window, &mouseX, &mouseY);

int mouseIsPressed = glfwGetMouseButton(window, 0);
int mouseIsPressed = glfwGetMouseButton(window, 0);

LUA_ADD_CONST_NUMBER_GLOBAL(L, mouseX);
LUA_ADD_CONST_NUMBER_GLOBAL(L, mouseY);
LUA_ADD_CONST_NUMBER_GLOBAL(L, mouseX);
LUA_ADD_CONST_NUMBER_GLOBAL(L, mouseY);

LUA_ADD_CONST_BOOL_GLOBAL(L, mouseIsPressed);
LUA_ADD_CONST_BOOL_GLOBAL(L, mouseIsPressed);
}

static void lu5_register_constants(lua_State *L)
{
LUA_ADD_NUMBER_GLOBAL(L, "LEFT_ARROW", 263);
LUA_ADD_NUMBER_GLOBAL(L, "RIGHT_ARROW", 262);
LUA_ADD_NUMBER_GLOBAL(L, "UP_ARROW", 265);
LUA_ADD_NUMBER_GLOBAL(L, "DOWN_ARROW", 264);
LUA_ADD_NUMBER_GLOBAL(L, "ENTER", 257);
LUA_ADD_NUMBER_GLOBAL(L, "BACKSPACE", 259);
LUA_ADD_NUMBER_GLOBAL(L, "LEFT_ARROW", 263);
LUA_ADD_NUMBER_GLOBAL(L, "RIGHT_ARROW", 262);
LUA_ADD_NUMBER_GLOBAL(L, "UP_ARROW", 265);
LUA_ADD_NUMBER_GLOBAL(L, "DOWN_ARROW", 264);
LUA_ADD_NUMBER_GLOBAL(L, "ENTER", 257);
LUA_ADD_NUMBER_GLOBAL(L, "BACKSPACE", 259);
}

void lu5_register_symbols(lua_State *L)
{
LUA_ADD_STRING_GLOBAL(L, "VERSION", LU5_VERSION);
LUA_ADD_STRING_GLOBAL(L, "VERSION", LU5_VERSION);

LUA_ADD_FUNCTION(L, print);
LUA_ADD_FUNCTION(L, print);

LUA_ADD_FUNCTION(L, createWindow);
LUA_ADD_FUNCTION(L, background);
LUA_ADD_FUNCTION(L, createWindow);
LUA_ADD_FUNCTION(L, background);

LUA_ADD_FUNCTION(L, isKeyDown);

LUA_ADD_FUNCTION(L, isKeyDown);

LUA_ADD_FUNCTION(L, fill);
LUA_ADD_FUNCTION(L, noFill);
LUA_ADD_FUNCTION(L, stroke);
LUA_ADD_FUNCTION(L, noStroke);
LUA_ADD_FUNCTION(L, strokeWeight);
LUA_ADD_FUNCTION(L, textSize);
LUA_ADD_FUNCTION(L, textFont);
LUA_ADD_FUNCTION(L, strokeWeight);
LUA_ADD_FUNCTION(L, textSize);
LUA_ADD_FUNCTION(L, textFont);

LUA_ADD_FUNCTION(L, loadFont);
LUA_ADD_FUNCTION(L, loadFont);

LUA_ADD_FUNCTION(L, point);
LUA_ADD_FUNCTION(L, circle);
LUA_ADD_FUNCTION(L, ellipse);
LUA_ADD_FUNCTION(L, square);
LUA_ADD_FUNCTION(L, rect);
LUA_ADD_FUNCTION(L, circle);
LUA_ADD_FUNCTION(L, ellipse);
LUA_ADD_FUNCTION(L, square);
LUA_ADD_FUNCTION(L, rect);
LUA_ADD_FUNCTION(L, quad);
LUA_ADD_FUNCTION(L, line);
LUA_ADD_FUNCTION(L, line);
LUA_ADD_FUNCTION(L, triangle);
LUA_ADD_FUNCTION(L, text);
LUA_ADD_FUNCTION(L, arc);

LUA_ADD_FUNCTION_BY_NAME(L, "round", lu5_round);
LUA_ADD_FUNCTION_BY_NAME(L, "ceil", lu5_ceil);
LUA_ADD_FUNCTION_BY_NAME(L, "floor", lu5_floor);
LUA_ADD_FUNCTION_BY_NAME(L, "sin", lu5_sin);
LUA_ADD_FUNCTION_BY_NAME(L, "cos", lu5_cos);
LUA_ADD_FUNCTION_BY_NAME(L, "tan", lu5_tan);
LUA_ADD_FUNCTION_BY_NAME(L, "round", lu5_round);
LUA_ADD_FUNCTION_BY_NAME(L, "ceil", lu5_ceil);
LUA_ADD_FUNCTION_BY_NAME(L, "floor", lu5_floor);
LUA_ADD_FUNCTION_BY_NAME(L, "sin", lu5_sin);
LUA_ADD_FUNCTION_BY_NAME(L, "cos", lu5_cos);
LUA_ADD_FUNCTION_BY_NAME(L, "tan", lu5_tan);

lu5_register_constants(L);
}

void lu5_register_number_array(lua_State *L, const char* array_name, double *list, size_t size)
{
lua_newtable(L);
lua_newtable(L);

for (int i = 0; i < size; i++) {
lua_pushnumber(L, i+1);
lua_pushnumber(L, list[i]);
lua_settable(L, -3);
}
for (int i = 0; i < size; i++) {
lua_pushnumber(L, i+1);
lua_pushnumber(L, list[i]);
lua_settable(L, -3);
}

lua_setglobal(L, array_name);
lua_setglobal(L, array_name);
}

void lu5_register_integer_array(lua_State *L, const char* array_name, int *list, size_t size)
{
lua_newtable(L);
lua_newtable(L);

for (int i = 0; i < size; i++) {
lua_pushnumber(L, i+1);
lua_pushinteger(L, list[i]);
lua_settable(L, -3);
}
for (int i = 0; i < size; i++) {
lua_pushnumber(L, i+1);
lua_pushinteger(L, list[i]);
lua_settable(L, -3);
}

lua_setglobal(L, array_name);
lua_setglobal(L, array_name);
}

void lu5_register_string_array(lua_State *L, const char* array_name, const char **list, size_t size)
{
lua_newtable(L);
lua_newtable(L);

for (int i = 0; i < size; i++) {
lua_pushnumber(L, i+1);
lua_pushstring(L, list[i]);
lua_settable(L, -3);
}
for (int i = 0; i < size; i++) {
lua_pushnumber(L, i+1);
lua_pushstring(L, list[i]);
lua_settable(L, -3);
}

lua_setglobal(L, array_name);
lua_setglobal(L, array_name);
}

0 comments on commit ef882ad

Please sign in to comment.