Add testing module: lang

This commit is contained in:
Qwreey 2023-02-17 02:30:51 +09:00
parent 9e1216c761
commit 6ce0759fac
5 changed files with 56 additions and 37 deletions

View file

@ -14,11 +14,12 @@ local store = require "store"
local class = require "class" local class = require "class"
local mount = require "mount" local mount = require "mount"
local signal = require "signal" local signal = require "signal"
-- local lang = require "lang" local lang = require "lang"
-- submodule -- submodule
local _,advancedTween = pcall(require,"libs.AdvancedTween") local _,advancedTween = pcall(require,"libs.AdvancedTween")
local _,round = pcall(require,"libs.round") local _,round = pcall(require,"libs.round")
local _,customWarn = pcall(require,"libs.customWarn")
local idSpace = {} local idSpace = {}
@ -38,10 +39,7 @@ function module.Init(id)
local this = {__type = "quad_module_init"} local this = {__type = "quad_module_init"}
this.require = require this.require = require
this.warn = function(err) this.warn = customWarn or warn
warn(tostring(err))
print(debug.traceback())
end
this.Round = type(round) == "table" and round ---@type quad_module_round this.Round = type(round) == "table" and round ---@type quad_module_round
this.Tween = type(advancedTween) == "table" and advancedTween ---@type quad_module_tween this.Tween = type(advancedTween) == "table" and advancedTween ---@type quad_module_tween
this.Signal = signal.init(this) ---@type quad_module_signal this.Signal = signal.init(this) ---@type quad_module_signal
@ -50,6 +48,7 @@ function module.Init(id)
this.Store = store.init(this) ---@type quad_module_store this.Store = store.init(this) ---@type quad_module_store
this.Mount = mount.init(this) ---@type quad_module_mount this.Mount = mount.init(this) ---@type quad_module_mount
this.Class = class.init(this) ---@type quad_module_class this.Class = class.init(this) ---@type quad_module_class
this.Lang = lang.init(this) ---@type quad_module_lang
-- save -- save
if id then if id then

11
src/lang.lua Normal file
View file

@ -0,0 +1,11 @@
local module = {}
function module.init(shared)
---@class quad_module_lang
local new = {}
return new
end
return module

4
src/libs/customWarn.lua Normal file
View file

@ -0,0 +1,4 @@
return function(err)
warn(tostring(err))
print(debug.traceback())
end

View file

@ -1,74 +1,74 @@
local module = {}; local module = {}
local insert = table.insert; local insert = table.insert
---@param shared quad_export ---@param shared quad_export
---@return quad_module_style ---@return quad_module_style
function module.init(shared) function module.init(shared)
local warn = shared.warn; local warn = shared.warn
---@class quad_module_style ---@class quad_module_style
local new = {__type = "quad_module_style"}; local new = {__type = "quad_module_style"}
local styles = {}; local styles = {}
new.Styles = styles; new.Styles = styles
---@class quad_style ---@class quad_style
local styleClass = {__type = "quad_style"}; local styleClass = {__type = "quad_style"}
styleClass.__index = styleClass; styleClass.__index = styleClass
function new.New(props) function new.New(props)
return setmetatable(props,styleClass); return setmetatable(props,styleClass)
end end
local newStyle = new.New; local newStyle = new.New
setmetatable(new,{ setmetatable(new,{
---@return quad_style ---@return quad_style
__call = function (_,styleTable) __call = function (_,styleTable)
if type(styleTable) == "string" then if type(styleTable) == "string" then
return function (nstyleTable) return function (nstyleTable)
local this = newStyle(nstyleTable); local this = newStyle(nstyleTable)
styles[styleTable] = this; styles[styleTable] = this
return this; return this
end end
end end
return newStyle(styleTable); return newStyle(styleTable)
end end
}); })
local function recursionStyleParse(style,parseTable) local function recursionStyleParse(style,parseTable)
for _,value in ipairs(parseTable) do for _,value in ipairs(parseTable) do
if value == style then if value == style then
warn("[Quad] infinity recursion detected on parsing style. ignored recursion"); warn("[Quad] infinity recursion detected on parsing style. ignored recursion")
return; return
end end
end end
insert(parseTable,style); insert(parseTable,style)
for key,value in pairs(style) do for key,value in pairs(style) do
if type(key) == "number" and type(value) == "table" and value.__type == "quad_style" then if type(key) == "number" and type(value) == "table" and value.__type == "quad_style" then
recursionStyleParse(value,parseTable); recursionStyleParse(value,parseTable)
end end
end end
end end
local parsed = {}; local parsed = {}
function new.ParseStyles(style) function new.ParseStyles(style)
do -- check cache do -- check cache
local cached = parsed[style]; local cached = parsed[style]
if cached then return cached; end if cached then return cached end
end end
-- type check -- type check
if type(style) ~= "table" or style.__type ~= "quad_style" then if type(style) ~= "table" or style.__type ~= "quad_style" then
error(("Unknown type type '%s:%s' got"):format(tostring(style),tostring(type(style)))); error(("Unknown type type '%s:%s' got"):format(tostring(style),tostring(type(style))))
end end
local this = {} local this = {}
recursionStyleParse(style,this); recursionStyleParse(style,this)
parsed[style] = this; parsed[style] = this
return this; return this
end end
return new; return new
end end
return module; return module

View file

@ -175,27 +175,32 @@ export type module_tween = {
} }
------------------- -------------------
-- module_signal -- module_round
------------------- -------------------
export type round = { export type module_round = {
SetRound: (ImageFrame:ImageLabel|ImageButton,RoundSize:number)->(ImageLabel|ImageButton); SetRound: (ImageFrame:ImageLabel|ImageButton,RoundSize:number)->(ImageLabel|ImageButton);
SetOutline: (ImageFrame:ImageLabel|ImageButton,RoundSize:number)->(ImageLabel|ImageButton); SetOutline: (ImageFrame:ImageLabel|ImageButton,RoundSize:number)->(ImageLabel|ImageButton);
GetRound: (ImageFrame:ImageLabel|ImageButton)->number; GetRound: (ImageFrame:ImageLabel|ImageButton)->number;
GetOutline: (ImageFrame:ImageLabel|ImageButton)->number; GetOutline: (ImageFrame:ImageLabel|ImageButton)->number;
} }
-------------------
-- module_signal
-------------------
export type module_lang = {}
------------------- -------------------
-- module -- module
------------------- -------------------
export type module_exported = { export type module_exported = {
Round: round; Signal: module_signal;
Round: module_round;
Tween: module_tween; Tween: module_tween;
Style: module_style; Style: module_style;
Event: module_event; Event: module_event;
Store: module_store; Store: module_store;
Mount: module_mount; Mount: module_mount;
Class: module_class; Class: module_class;
Signal: module_signal;
Lang: module_lang; Lang: module_lang;
} }
export type module = { export type module = {