From 92ccea08837c9efdcb03417123b60d96c9d436ed Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 26 Dec 2025 03:19:09 +0100 Subject: [PATCH] lua --- Makefile | 22 +++++++++++++++++++--- lua_advanced/Makefile | 2 +- lua_advanced/main.c | 2 ++ lua_advanced/script.lua | 22 ++++++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 79ce3cd..abd2ba5 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,18 @@ SRC := $(wildcard *.c) OBJ := $(SRC:.c=.o) ELF := $(SRC:.c=.elf) +SUBDIRS += buf +SUBDIRS += cjson +SUBDIRS += dynbuf +SUBDIRS += filters +SUBDIRS += hashmap +SUBDIRS += linalg +SUBDIRS += lua_advanced +SUBDIRS += lua_embed +SUBDIRS += message +SUBDIRS += socket +SUBDIRS += sqlite + %.o: %.c @echo CC $@ @$(CC) $(CFLAGS) -c -o $@ $< @@ -21,6 +33,9 @@ ELF := $(SRC:.c=.elf) @$(CC) $(LIBS) -o $@ $< all: $(ELF) + @for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir; \ + done sub: @-find . -mindepth 1 -maxdepth 1 -type d -exec make --no-print-directory -C {} \; @@ -35,8 +50,9 @@ format: clang-format -i $(shell git ls-files '*.c' '*.h') clean: - @echo "Cleaning up..." - @rm -rf $(OBJ) $(ELF) *.json .cache - @find . -mindepth 1 -maxdepth 1 -type d -exec make --no-print-directory -C {} clean \; + rm -rf $(OBJ) $(ELF) *.json .cache + @for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir clean; \ + done .PHONY: format diff --git a/lua_advanced/Makefile b/lua_advanced/Makefile index a770e06..0ff85ee 100644 --- a/lua_advanced/Makefile +++ b/lua_advanced/Makefile @@ -2,7 +2,7 @@ CC = gcc CFLAGS = -Wall -O2 TARGET = main.elf -SRC = main.c +SRC = main.c esc.c LDFLAGS += -lm LDFLAGS += -llua diff --git a/lua_advanced/main.c b/lua_advanced/main.c index 613f854..bd97e1a 100644 --- a/lua_advanced/main.c +++ b/lua_advanced/main.c @@ -1,3 +1,4 @@ +#include "esc.h" #include #include #include @@ -42,6 +43,7 @@ int main(void) { lua_State *L = luaL_newstate(); luaL_openlibs(L); // Load Lua standard libraries + register_esc(L); // luaL_requiref(L, "_G", luaopen_base, 1); // const lua_Number ver = lua_version(NULL); diff --git a/lua_advanced/script.lua b/lua_advanced/script.lua index c1c0ea7..eb0f4b9 100644 --- a/lua_advanced/script.lua +++ b/lua_advanced/script.lua @@ -11,3 +11,25 @@ function printvec(v) end vec = { x = 1.0, y = 2.0, z = 3.0 } printvec(vec) + +--- Enumerate symbols in namespace +---@param t +function dir(t) + for k, v in pairs(t) do + print(k, type(v)) + end +end + +dir(esc) +-- get config +local cfg = esc.get_esc_config() +print(cfg.maxspeed, cfg.odometer, cfg.started) + +-- modify +esc.set_maxspeed(200) +esc.set_started(true) +esc.add_odometer(5.5) + +-- see changes +cfg = esc.get_esc_config() +print(cfg.maxspeed, cfg.odometer, cfg.started)