置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:Sandbox/九江月/test

猛汉♂百科,万男皆可猛的百科全书!转载请标注来源页面的网页链接,并声明引自猛汉百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
local Core={
	iFlow={index=1,level=0},
	Card={
		Meta={originalcode={"originalcode",0},code={"code",0},originalcoderule={"code",0}}
	},
	Effect={
		Meta={description={"description",0},category={"category",0},type={"type",0},code={"code",0},property={"property",0},
			countLimit={"countLimit",0,0},range={"range",0,0},targetrange={"targetrange",0,0},value={"value",0,0},
			condition={"condition",0},cost={"cost",0},target={"target",0},operation={"operation",0}}
	}
}
--split
local function split( str,reps )
    local resultStrList = {}
    string.gsub(str,'[^'..reps..']+',function ( w )
        table.insert(resultStrList,w)
    end)
    return resultStrList
end
--return
function Core.Return(frame,index,args) return args[2] end
--callback
function Core.Callback(frame,index,args)
	return  ((args[1]~=0 and Core[frame.args[index+1]]~=nil) and {Core[frame.args[index+1]](frame,index+2,args)} or {Core.Return(frame,index,args)})[1]
end
--flowcontrol
function Core.If(frame,index,args)
	Core.iFlow.level = Core.iFlow.level + 1
	return Core.Callback(frame,index,args)
end
function Core.Then(frame,index,args)
	return Core.Callback(frame,index-1,args)
end
function Core.Else(frame,index,args)
	Core.iFlow.index = Core.iFlow.index * -1
	return Core.Callback(frame,index-1,args)
end
function Core.End(frame,index,args)
	Core.iFlow.level = (Core.iFlow.level == 0 and {0} or {Core.iFlow.level - 1})[1]
	return Core.Callback(frame,index-1,args)
end
--bool
function Core.Bool(frame,index,args,b,op)
	if not args then args={} end
	if not index then index = 1 end
	args[3] = args[2]
	args[2] = b
	if op == "and" then args[2] = (args[3] and args[2]) end
	if op == "or" then args[2] = (args[3] or args[2]) end
	if op == "not" then args[2] = (not args[2]) end
	if op == "and not" then args[2] = (args[3] and not args[2]) end
	if op == "or not" then args[2] = (args[3] or not args[2]) end
    return Core.Callback(frame,index,args)
end
--bool logic
function Core.True(frame,index,args)
	if not args then args={} end
	if not index then index = 1 end
	return Core.Bool(frame,index-1,args,true,args[1])
end
function Core.False(frame,index,args) 
	if not args then args={} end
	if not index then index = 1 end
	return Core.Bool(frame,index-1,args,false,args[1])
end
function Core.And(frame,index,args)
	args[1] = "and"
	return Core.Bool(frame,index-1,args,args[2])
end
function Core.Or(frame,index,args)
	args[1] = "or"
	return Core.Bool(frame,index-1,args,args[2])
end
function Core.Not(frame,index,args)
	if not args then args={} end
	if not index then index = 1 end
	local sw = {
		["and"] = function(name) args[2] = args[3] return "and not" end,
		["or"] = function(name) args[2] = args[3] return "or not" end,
		["#default"] = function(name) return (name=="not" and {""} or {"not"})[1] end
	}
	local f =(sw[args[1]] and {sw[args[1]]} or {sw["#default"]})[1]
	args[1] = f(args[1])
	return Core.Bool(frame,index-1,args,args[2])
end
--init
function Core.CardInit(frame)
	local index = 1
	local str = string.gsub(frame.args[index], "%%;", "%%3B") 
	local args = split(str,';')
	local switch={
        ["#default"]=function(text) 
            local strbegin = -1
            local strend = string.find(text,":",strbegin + 1)  
            local tpara = (strend and {string.sub(text, strbegin+1,strend-1)} or {"#query"})[1] 
            local tvalue = (strend and {string.sub(text,strend+1)} or {string.sub(text, strbegin+1)})[1] 
            if tpara~="#query" then
        		Core.Card.Meta[tpara]={tostring(tpara),tvalue}
        	end
        end
    }
	for k,v in pairs(args) do
    	v = string.gsub(v, "%%3B", ";") 
        local f = switch["#default"]
        if(f) then
            f(v)  
        end
    end
    return Core.Callback(frame,index,{1})
end
function Core.CardGetMeta(frame,index,args)
	local ret = ""
	for k,v in pairs(Core.Card.Meta) do
		ret = ret..v[1]..":"..v[2]..";"
	end
	return  Core.Callback(frame,index,{0,ret})
end
--set
function Core.CardSetCode(frame,index,args)
	index = (index==nil and {1} or {index})[1]
	Core.Card.Meta.code[2] = frame.args[index]
	return Core.Callback(frame,index,{1})
end
function Core.CardSetOriginalCode(frame,index,args)
	index = (index==nil and {1} or {index})[1]
	Core.Card.Meta.originalcode[2] = frame.args[index]
	return Core.Callback(frame,index,{1})
end
function Core.CardSetOriginalCodeRule(frame,index,args)
	index = (index==nil and {1} or {index})[1]
	Core.Card.Meta.originalcoderule[2] = frame.args[index]
	return Core.Callback(frame,index,{1})
end
function Core.CardSetFusionCode(frame,index,args)
	index = (index==nil and {1} or {index})[1]
	Core.Card.Meta.fusioncode[2] = frame.args[index]
	return Core.Callback(frame,index,{1})
end
--get
function Core.CardGetCode(frame,index,args) 
	local ret = Core.Card.Meta.code[2] or 'nil value'
	return Core.Callback(frame,index,{0,ret})
end
function Core.CardGetOriginalCode(frame,index,args) 
	local ret = Core.Card.Meta.originalcode[2] or 'nil value'
	return Core.Callback(frame,index,{0,ret})
end
function Core.CardGetOriginalCodeRule(frame,index,args) 
	local ret = Core.Card.Meta.originalcoderule[2] or 'nil value'
	return Core.Callback(frame,index,{0,ret})
end
function Core.CardGetFusionCode(frame,index,args) 
	local ret = Core.Card.Meta.fusioncode[2] or 'nil value'
	return Core.Callback(frame,index,{0,ret})
end
--ifget
function Core.CardIsCode(frame,index,args) 
	local ret = ((tostring(Core.Card.Meta.code[2]) == frame.args[index]) and {true} or {false})[1]
	return Core.Bool(frame,index,args,ret,args[1])
end

return Core