From 7b33667e0486485f00f4a2faa61cbd1a1ac091d5 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Sun, 20 Feb 2022 20:29:04 +0100 Subject: [PATCH] added tinker_core as lib --- Makefile | 19 +++++++++++++------ build.hxml | 4 +++- minify.js | 4 ++-- src/polyfill.lua | 22 ++++++++++++++++++++++ 4 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 src/polyfill.lua diff --git a/Makefile b/Makefile index 1e37cb2..e1a6e67 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,27 @@ -BIN_NAME := Haxe.lua -MINIFYD_NAME := Haxe.min.lua +BUNDLE_NAME = bundle.lua +HAXE_NAME = haxe.lua +MINIFYD_NAME := bundle.min.lua BUILD_DIR := build HAXE_FLAGS = -D webconsole +POLYFILLED_NAME = bundle.polyfill.lua +POLYFILL_SRC = src/polyfill.lua -BIN_PATH := $(BUILD_DIR)/$(BIN_NAME) +HAXE_PATH := $(BUILD_DIR)/$(HAXE_NAME) MIN_PATH := $(BUILD_DIR)/$(MINIFYD_NAME) +POLYFILL_PATH := $(BUILD_DIR)/$(POLYFILLED_NAME) all: clean $(MIN_PATH) build: $(MIN_PATH) -$(BIN_PATH): $(shell find src -name '*.hx') +$(HAXE_PATH): $(shell find src -name '*.hx') haxe build.hxml $(HAXE_FLAGS) -$(MIN_PATH): $(BIN_PATH) - node minify.js $@ +$(MIN_PATH): $(POLYFILL_PATH) + node minify.js $(POLYFILL_PATH) $@ + +$(POLYFILL_PATH): $(POLYFILL_SRC) $(HAXE_PATH) + cat $(POLYFILL_SRC) $(HAXE_PATH) > $@ deps: package.json build.hxml haxelib install all --always && yarn install diff --git a/build.hxml b/build.hxml index 31ac015..83fe752 100644 --- a/build.hxml +++ b/build.hxml @@ -2,8 +2,10 @@ --main Startup --library cctweaked:git:https://git.kapelle.org/niklas/cctweaked-haxelib.git +--library tink_core --dce full ---lua build/Haxe.lua +--lua build/haxe.lua -D lua-vanilla +-D lua-ver 5.1 diff --git a/minify.js b/minify.js index f8a92d9..8e7b032 100644 --- a/minify.js +++ b/minify.js @@ -1,10 +1,10 @@ const fs = require("fs"); const luamin = require("luamin"); -const haxeOutput = fs.readFileSync("build/Haxe.lua",{encoding:"utf8"}); +const haxeOutput = fs.readFileSync(process.argv[2] ?? "build/Haxe.min.lua",{encoding:"utf8"}); const minified = luamin.minify(haxeOutput); -fs.writeFileSync(process.argv[2] ?? "build/Haxe.min.lua",minified); +fs.writeFileSync(process.argv[3] ?? "build/Haxe.min.lua",minified); console.log("minified lua"); diff --git a/src/polyfill.lua b/src/polyfill.lua new file mode 100644 index 0000000..4eed02b --- /dev/null +++ b/src/polyfill.lua @@ -0,0 +1,22 @@ +-- Polyfill require function +_G.require = function (module) + -- Polyfill luv package + if module == "luv" then + local module = {} + local metatable = { + __index = function(t, i) + -- Polyfill gettimeofday + if i == "gettimeofday" then + return function () + local mil = os.epoch() + return mil / 1000, mil + end + else + print("ERROR: Tell a dev to implement: " .. i) + end + end + } + setmetatable(module, metatable) + return module + end +end