rename globals to have a single uppercase letter

This commit is contained in:
Kartik K. Agaram 2022-12-25 15:51:39 -08:00
parent e0517b7149
commit 8add8ee51d

View File

@ -29,12 +29,12 @@ on = {}
function live.initialize(arg)
-- version control
Live.Head = 0
Live.Next_version = 1
Live.History = {} -- array of filename roots corresponding to each numeric prefix
Live.Manifest = {} -- mapping from roots to numeric prefixes as of version Live.Head
Live.head = 0
Live.next_version = 1
Live.history = {} -- array of filename roots corresponding to each numeric prefix
Live.manifest = {} -- mapping from roots to numeric prefixes as of version Live.head
live.load_files_so_far()
Live.Previous_read = 0
Live.previous_read = 0
if on.load then on.load() end
end
@ -48,12 +48,12 @@ function live.load_files_so_far()
live.append_files_with_numeric_prefix(love.filesystem.getSaveDirectory(), files)
table.sort(files)
live.check_integrity(files)
Live.History = live.load_history(files)
Live.Next_version = #Live.History + 1
Live.history = live.load_history(files)
Live.next_version = #Live.history + 1
local head_string = love.filesystem.read('head')
Live.Head = tonumber(head_string)
if Live.Head > 0 then
Live.Manifest = json.decode(love.filesystem.read(live.versioned_manifest(Live.Head)))
Live.head = tonumber(head_string)
if Live.head > 0 then
Live.manifest = json.decode(love.filesystem.read(live.versioned_manifest(Live.head)))
end
live.load_everything_in_manifest()
end
@ -118,7 +118,7 @@ end
function live.load_everything_in_manifest()
local files_to_load = {}
for k,v in pairs(Live.Manifest) do
for k,v in pairs(Live.manifest) do
if k ~= 'parent' then
local root, index = k, v
local filename = live.versioned_filename(index, root)
@ -144,13 +144,13 @@ end
-- ========= on each frame, check for messages and alter the app as needed
function live.update(dt)
if Current_time - Live.Previous_read > 0.1 then
if Current_time - Live.previous_read > 0.1 then
local buf = live.receive()
if buf then
live.run(buf)
if on.code_change then on.code_change() end
end
Live.Previous_read = Current_time
Live.previous_read = Current_time
end
end
@ -209,42 +209,42 @@ function live.run(buf)
if cmd == 'QUIT' then
love.event.quit(1)
elseif cmd == 'MANIFEST' then
live.send(json.encode(Live.Manifest))
live.send(json.encode(Live.manifest))
elseif cmd == 'DELETE' then
local binding = buf:match('^%S+%s+(%S+)')
Live.Manifest[binding] = nil
Live.manifest[binding] = nil
live.eval(binding..' = nil')
local next_filename = live.versioned_filename(Live.Next_version, binding)
local next_filename = live.versioned_filename(Live.next_version, binding)
love.filesystem.write(next_filename, '')
table.insert(Live.History, binding)
Live.Manifest.parent = Live.Head
local manifest_filename = live.versioned_manifest(Live.Next_version)
love.filesystem.write(manifest_filename, json.encode(Live.Manifest))
Live.Head = Live.Next_version
love.filesystem.write('head', tostring(Live.Head))
Live.Next_version = Live.Next_version + 1
table.insert(Live.history, binding)
Live.manifest.parent = Live.head
local manifest_filename = live.versioned_manifest(Live.next_version)
love.filesystem.write(manifest_filename, json.encode(Live.manifest))
Live.head = Live.next_version
love.filesystem.write('head', tostring(Live.head))
Live.next_version = Live.next_version + 1
elseif cmd == 'GET' then
local binding = buf:match('^%S+%s+(%S+)')
live.send(live.get_binding(binding))
-- other commands go here
else
local binding = cmd
local next_filename = live.versioned_filename(Live.Next_version, binding)
local next_filename = live.versioned_filename(Live.next_version, binding)
love.filesystem.write(next_filename, buf)
table.insert(Live.History, binding)
Live.Manifest[binding] = Live.Next_version
Live.Manifest.parent = Live.Head
local manifest_filename = live.versioned_manifest(Live.Next_version)
love.filesystem.write(manifest_filename, json.encode(Live.Manifest))
Live.Head = Live.Next_version
love.filesystem.write('head', tostring(Live.Head))
Live.Next_version = Live.Next_version + 1
table.insert(Live.history, binding)
Live.manifest[binding] = Live.next_version
Live.manifest.parent = Live.head
local manifest_filename = live.versioned_manifest(Live.next_version)
love.filesystem.write(manifest_filename, json.encode(Live.manifest))
Live.head = Live.next_version
love.filesystem.write('head', tostring(Live.head))
Live.next_version = Live.next_version + 1
local status, err = live.eval(buf)
if not status then
-- roll back
Live.Head = Live.Manifest.parent
local previous_manifest_filename = live.versioned_manifest(Live.Head)
Live.Manifest = json.decode(love.filesystem.read(previous_manifest_filename))
Live.head = Live.manifest.parent
local previous_manifest_filename = live.versioned_manifest(Live.head)
Live.manifest = json.decode(love.filesystem.read(previous_manifest_filename))
-- throw an error
live.send('ERROR '..tostring(err))
end
@ -253,8 +253,8 @@ function live.run(buf)
end
function live.get_binding(name)
if Live.Manifest[name] then
return love.filesystem.read(live.versioned_filename(Live.Manifest[name], name))
if Live.manifest[name] then
return love.filesystem.read(live.versioned_filename(Live.manifest[name], name))
end
end