From bc41cc3a244bf47679d1c47d17006a2aa7356bc8 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 29 Jan 2019 16:16:45 -0800 Subject: Switched to have colors/utf8 be optional, fixed an issue with currently running files leaking when errors occurred (causing spurious circular import errors), and improved tutorial. --- nomsu.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'nomsu.lua') diff --git a/nomsu.lua b/nomsu.lua index dc5b97f..21e4af2 100644 --- a/nomsu.lua +++ b/nomsu.lua @@ -1,16 +1,17 @@ local clibtype = package.cpath:match("?%.(so)") or package.cpath:match("?%.(dll)") +COLOR_ENABLED = true if clibtype == "dll" then + local enable_colors = require('wincolors') + local ok, _ = pcall(enable_colors) + if not ok then + COLOR_ENABLED = false + end os.execute("chcp 65001>nul") end if NOMSU_VERSION and NOMSU_PREFIX then package.path = tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(NOMSU_VERSION) .. "/?.lua;" .. package.path package.cpath = tostring(NOMSU_PREFIX) .. "/lib/nomsu/" .. tostring(NOMSU_VERSION) .. "/?." .. tostring(clibtype) .. ";" .. package.cpath end -local EXIT_SUCCESS, EXIT_FAILURE = 0, 1 -if _VERSION == "Lua 5.1" and not jit then - print("Sorry, Nomsu does not run on Lua 5.1. Please use LuaJIT 2+ or Lua 5.2+") - os.exit(EXIT_FAILURE) -end local usage = [=[Nomsu Compiler Usage: (nomsu | lua nomsu.lua | moon nomsu.moon) [-V version] [--help | -h] [--version] [-O optimization level] [-v] [-c] [-s] [-d debugger] [--no-core] [(file | -t tool | -e "nomsu code..." | files... -- ) [nomsu args...]] @@ -92,7 +93,7 @@ local arg_string = table.concat(arg, sep) .. sep local args, err = parser:match(arg_string) if not args or err or args.help then if err then - print("Didn't understand: \x1b[31;1m" .. tostring(err) .. "\x1b[0m") + print("Didn't understand: " .. tostring(err)) end print(usage) os.exit(EXIT_FAILURE) @@ -142,6 +143,7 @@ nomsu_environment.COMMAND_LINE_ARGS = nomsu_args nomsu_environment.OPTIMIZATION = optimization nomsu_environment.NOMSU_PACKAGEPATH = NOMSU_PACKAGEPATH nomsu_environment.NOMSU_PREFIX = NOMSU_PREFIX +nomsu_environment.COLOR_ENABLED = COLOR_ENABLED local run run = function() if not (args.no_core) then -- cgit v1.2.3