From e3cd6a03fa8ae09d0953f2eed1e2540d00b4949b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Vavru=C5=A1a?= <marek.vavrusa@nic.cz>
Date: Wed, 8 Apr 2015 16:21:24 +0200
Subject: [PATCH] build: compile Lua bytecode for embedded code

---
 config.mk        | 1 +
 daemon/daemon.mk | 5 +++--
 daemon/engine.c  | 3 +++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/config.mk b/config.mk
index 004fced6a..78d1340d8 100644
--- a/config.mk
+++ b/config.mk
@@ -17,5 +17,6 @@ CFLAGS  += -DPACKAGE_VERSION="\"$(MAJOR).$(MINOR)\"" -DPREFIX="\"$(PREFIX)\"" -D
 RM	:= rm -f
 LN      := ln -s
 XXD     ?= xxd
+LUAC    ?= luac
 INSTALL := install
 PYTHON  := python
diff --git a/daemon/daemon.mk b/daemon/daemon.mk
index 918738d55..64510f0df 100644
--- a/daemon/daemon.mk
+++ b/daemon/daemon.mk
@@ -10,8 +10,9 @@ kresolved_SOURCES := \
 # Embed resources
 daemon/engine.o: daemon/lua/init.inc daemon/lua/config.inc
 %.inc: %.lua
-	@$(call quiet,XXD,$<) -i < $< > $@
-	@echo ', 0x00' >> $@
+	@$(call quiet,LUAC,$<) -o $<.out $<
+	@$(call quiet,XXD,$<) -i - < $<.out > $@
+	@$(RM) $<.out
 
 # Dependencies
 kresolved_DEPEND := $(libkresolve)
diff --git a/daemon/engine.c b/daemon/engine.c
index 8d33a4d2f..ae94b09da 100644
--- a/daemon/engine.c
+++ b/daemon/engine.c
@@ -192,6 +192,9 @@ int engine_cmd(struct engine *engine, const char *str)
 	return kr_ok();
 }
 
+/* Execute byte code */
+#define l_dobytecode(L, arr, len, name) \
+	(luaL_loadbuffer((L), (arr), (len), (name)) || lua_pcall((L), 0, LUA_MULTRET, 0))
 static int engine_loadconf(struct engine *engine)
 {
 	/* Init environment */
-- 
GitLab