Initial commit
This commit is contained in:
76
lua/cave/python/script.lua
Normal file
76
lua/cave/python/script.lua
Normal file
@@ -0,0 +1,76 @@
|
||||
local Runnable = require "cave.python.runnable"
|
||||
local Meta = require "cave.meta"
|
||||
local Path = require "cave.path"
|
||||
local Context = require "cave.context"
|
||||
|
||||
local validate = Meta.validate
|
||||
|
||||
---@class cave.Python.Script : cave.Python.Runnable
|
||||
---@field file cave.Path
|
||||
local Script = Meta.derive("Python.Script", Runnable)
|
||||
|
||||
---@return cave.Python.Script
|
||||
function Script:script() return self end
|
||||
|
||||
---@return string
|
||||
function Script:valid_file()
|
||||
assert(self.file:is_file())
|
||||
return self.file:tostring()
|
||||
end
|
||||
|
||||
---@class cave.Python.Script.Factory : cave.Python.Runnable.Factory
|
||||
---@field file_ cave.Path
|
||||
local Factory = Meta.derive("Python.Script.Factory", Runnable.Factory)
|
||||
|
||||
---@param file cave.Path
|
||||
---@param context cave.Context
|
||||
function Factory:init(file, context)
|
||||
Runnable.Factory.init(self, context)
|
||||
self.file_ = file
|
||||
end
|
||||
|
||||
---@param other cave.Python.Script.Factory
|
||||
function Factory:copy_from(other)
|
||||
Runnable.Factory.copy_from(self, other)
|
||||
self.file_ = other.file_:copy()
|
||||
end
|
||||
|
||||
---@param file cave.Path
|
||||
---@param context cave.Context
|
||||
---@return cave.Python.Script.Factory
|
||||
function Factory.new(file, context)
|
||||
validate { file = { file, Path }, context = { context, Context } }
|
||||
local factory = setmetatable({}, Factory)
|
||||
factory:init(file, context)
|
||||
return factory
|
||||
end
|
||||
|
||||
---@return cave.Python.Script.Factory
|
||||
function Factory:copy()
|
||||
local factory = setmetatable({}, Factory)
|
||||
factory:copy_from(self)
|
||||
return factory
|
||||
end
|
||||
|
||||
---@return string
|
||||
function Factory:get_id() return self.id_ or ("[%s]"):format(self:get_file()) end
|
||||
|
||||
---@return cave.Path
|
||||
function Factory:get_file() return self.file_ end
|
||||
|
||||
---@param script cave.Python.Script
|
||||
function Factory:init_script(script)
|
||||
self:init_runnable(script)
|
||||
script.file = self:get_file()
|
||||
end
|
||||
|
||||
---@return cave.Python.Script
|
||||
function Factory:build()
|
||||
local script = setmetatable({}, Script)
|
||||
self:init_script(script)
|
||||
return script
|
||||
end
|
||||
|
||||
Script.Factory = Factory
|
||||
|
||||
return Script
|
||||
Reference in New Issue
Block a user