local Runnable = require "cave.python.runnable" local Context = require "cave.context" local Meta = require "cave.meta" local Str = Meta.String local validate = Meta.validate ---@class cave.Python.Module : cave.Python.Runnable ---@field name string local Module = Meta.derive("Python.Module", Runnable) function Module:module() return self end ---@class cave.Python.Module.Factory : cave.Python.Runnable.Factory ---@field name_ string local Factory = Meta.derive("Python.Module.Factory", Runnable.Factory) ---@param name string ---@param context cave.Context function Factory:init(name, context) Runnable.Factory.init(self, context) self.name_ = name end ---@param other cave.Python.Module.Factory function Factory:copy_from(other) Runnable.Factory.copy_from(self, other) self.name_ = other.name_ end ---@param name string ---@param context cave.Context ---@return cave.Python.Module.Factory function Factory.new(name, context) validate { name = { name, Str }, context = { context, Context } } local factory = setmetatable({}, Factory) factory:init(name, context) return factory end ---@return cave.Python.Module.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 self:get_name() end ---@return string function Factory:get_name() return self.name_ end ---@param module cave.Python.Module function Factory:init_module(module) self:init_runnable(module) module.name = self:get_name() end ---@return cave.Python.Module function Factory:build() local module = setmetatable({}, Module) self:init_module(module) return module end Module.Factory = Factory return Module