Removed underscore from start of globals, added VERSION

eg. `_SCALE` => `SCALE`
prevents conflict with lua's own _NAME globals
This commit is contained in:
rxi 2020-04-25 09:57:35 +01:00
parent bd43ed3e3f
commit c658b6f1ca
6 changed files with 30 additions and 27 deletions

View file

@ -62,7 +62,7 @@ command.add(nil, {
["core:open-project-file"] = function()
core.command_view:enter("Open Project File", function(text, item)
text = core.project_dir .. _PATHSEP .. (item and item.text or text)
text = core.project_dir .. PATHSEP .. (item and item.text or text)
core.root_view:open_doc(core.open_doc(text))
end, function(text)
local files = {}

View file

@ -91,7 +91,7 @@ function common.path_suggest(text)
local info = system.get_file_info(file)
if info then
if info.type == "dir" then
file = file .. _PATHSEP
file = file .. PATHSEP
end
if file:lower():find(text:lower(), nil, true) == 1 then
table.insert(res, file)

View file

@ -8,7 +8,7 @@ config.mouse_wheel_scroll = 50
config.file_size_limit = 10
config.symbol_pattern = "[%a_][%w_]*"
config.non_word_chars = " \t\n/\\()\"':,.;<>~!@#$%^&*|+=[]{}`?-"
config.treeview_size = 200 * _SCALE
config.treeview_size = 200 * SCALE
config.undo_merge_timeout = 0.3
config.max_undos = 10000
config.highlight_current_line = true

View file

@ -32,7 +32,7 @@ local function project_scan_thread()
for _, file in ipairs(all) do
if not file:find("^%.") then
local file = path .. _PATHSEP .. file
local file = path .. PATHSEP .. file
local info = system.get_file_info(file)
if info and info.size < size_limit then
table.insert(info.type == "dir" and dirs or files, file)
@ -86,9 +86,9 @@ function core.init()
core.project_files = {}
core.project_dir = "."
local info = _ARGS[2] and system.get_file_info(_ARGS[2])
local info = ARGS[2] and system.get_file_info(ARGS[2])
if info and info.type == "dir" then
core.project_dir = _ARGS[2]:gsub("[\\/]$", "")
core.project_dir = ARGS[2]:gsub("[\\/]$", "")
end
core.root_view = RootView()
@ -104,8 +104,8 @@ function core.init()
local got_plugin_error = not core.load_plugins()
local got_user_error = not core.try(require, "user")
for i = 2, #_ARGS do
local filename = _ARGS[i]
for i = 2, #ARGS do
local filename = ARGS[i]
local info = system.get_file_info(filename)
if info and info.type == "file" then
core.root_view:open_doc(core.open_doc(filename))
@ -146,7 +146,7 @@ end
function core.load_plugins()
local no_errors = true
local files = system.list_dir(_EXEDIR .. "/data/plugins")
local files = system.list_dir(EXEDIR .. "/data/plugins")
for _, filename in ipairs(files) do
local modname = "plugins." .. filename:gsub(".lua$", "")
local ok = core.try(require, modname)
@ -405,7 +405,7 @@ end
function core.on_error(err)
-- write error to file
local fp = io.open(_EXEDIR .. "/error.txt", "wb")
local fp = io.open(EXEDIR .. "/error.txt", "wb")
fp:write("Error: " .. tostring(err) .. "\n")
fp:write(debug.traceback(nil, 4))
fp:close()

View file

@ -1,16 +1,16 @@
local common = require "core.common"
local style = {}
style.padding = { x = common.round(14 * _SCALE), y = common.round(7 * _SCALE) }
style.divider_size = common.round(1 * _SCALE)
style.scrollbar_size = common.round(4 * _SCALE)
style.caret_width = common.round(2 * _SCALE)
style.tab_width = common.round(170 * _SCALE)
style.padding = { x = common.round(14 * SCALE), y = common.round(7 * SCALE) }
style.divider_size = common.round(1 * SCALE)
style.scrollbar_size = common.round(4 * SCALE)
style.caret_width = common.round(2 * SCALE)
style.tab_width = common.round(170 * SCALE)
style.font = renderer.font.load(_EXEDIR .. "/data/fonts/font.ttf", 14 * _SCALE)
style.big_font = renderer.font.load(_EXEDIR .. "/data/fonts/font.ttf", 34 * _SCALE)
style.icon_font = renderer.font.load(_EXEDIR .. "/data/fonts/icons.ttf", 14 * _SCALE)
style.code_font = renderer.font.load(_EXEDIR .. "/data/fonts/monospace.ttf", 13.5 * _SCALE)
style.font = renderer.font.load(EXEDIR .. "/data/fonts/font.ttf", 14 * SCALE)
style.big_font = renderer.font.load(EXEDIR .. "/data/fonts/font.ttf", 34 * SCALE)
style.icon_font = renderer.font.load(EXEDIR .. "/data/fonts/icons.ttf", 14 * SCALE)
style.code_font = renderer.font.load(EXEDIR .. "/data/fonts/monospace.ttf", 13.5 * SCALE)
style.background = { common.color "#1F1F2B" }
style.background2 = { common.color "#181821" }

View file

@ -88,27 +88,30 @@ int main(int argc, char **argv) {
lua_pushstring(L, argv[i]);
lua_rawseti(L, -2, i + 1);
}
lua_setglobal(L, "_ARGS");
lua_setglobal(L, "ARGS");
lua_pushstring(L, "1.01");
lua_setglobal(L, "VERSION");
lua_pushstring(L, SDL_GetPlatform());
lua_setglobal(L, "_PLATFORM");
lua_setglobal(L, "PLATFORM");
lua_pushnumber(L, get_scale());
lua_setglobal(L, "_SCALE");
lua_setglobal(L, "SCALE");
char exedir[2048];
get_exe_dir(exedir, sizeof(exedir));
lua_pushstring(L, exedir);
lua_setglobal(L, "_EXEDIR");
lua_setglobal(L, "EXEDIR");
(void) luaL_dostring(L,
"local core\n"
"xpcall(function()\n"
" _SCALE = tonumber(os.getenv(\"LITE_SCALE\")) or _SCALE\n"
" _PATHSEP = package.config:sub(1, 1)\n"
" package.path = _EXEDIR .. '/data/?.lua;' .. package.path\n"
" package.path = _EXEDIR .. '/data/?/init.lua;' .. package.path\n"
" SCALE = tonumber(os.getenv(\"LITE_SCALE\")) or SCALE\n"
" PATHSEP = package.config:sub(1, 1)\n"
" package.path = EXEDIR .. '/data/?.lua;' .. package.path\n"
" package.path = EXEDIR .. '/data/?/init.lua;' .. package.path\n"
" core = require('core')\n"
" core.init()\n"
" core.run()\n"