⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 container.lua

📁 cegui界面库
💻 LUA
📖 第 1 页 / 共 2 页
字号:

end

function classContainer:isenum (type)
 if global_enums[type] then
	return type
 else
 	return false
 end

 local basetype = gsub(type,"^.*::","")
 local env = self
 while env do
  if env.enums then
   local i=1
   while env.enums[i] do
    if env.enums[i].name == basetype then
         return true
        end
        i = i+1
   end
  end
  env = env.parent
 end
 return false
end

methodisvirtual = false -- a global

-- parse chunk
function classContainer:doparse (s)
--print ("parse "..s)

 -- try the parser hook
 do
 	local sub = parser_hook(s)
 	if sub then
 		return sub
 	end
 end

 -- try the null statement
 do
 	local b,e,code = string.find(s, "^%s*;")
 	if b then
 		return strsub(s,e+1)
 	end
 end

 -- try empty verbatim line
 do
 	local b,e,code = string.find(s, "^%s*$\n")
 	if b then
 		return strsub(s,e+1)
 	end
 end

 -- try Lua code
 do
  local b,e,code = strfind(s,"^%s*(%b\1\2)")
  if b then
   Code(strsub(code,2,-2))
   return strsub(s,e+1)
  end
 end

 -- try C code
 do
  local b,e,code = strfind(s,"^%s*(%b\3\4)")
  if b then
	code = '{'..strsub(code,2,-2)..'\n}\n'
	Verbatim(code,'r')        -- verbatim code for 'r'egister fragment
	return strsub(s,e+1)
  end
 end

 -- try C code for preamble section
 do
 	local b,e,code = string.find(s, "^%s*(%b\5\6)")
 	if b then
 		code = string.sub(code, 2, -2).."\n"
		Verbatim(code, '')
		return string.sub(s, e+1)
 	end
 end

 -- try default_property directive
 do
 	local b,e,ptype = strfind(s, "^%s*TOLUA_PROPERTY_TYPE%s*%(+%s*([^%)%s]*)%s*%)+%s*;?")
 	if b then
 		if not ptype or ptype == "" then
 			ptype = "default"
 		end
 		self:set_property_type(ptype)
	 	return strsub(s, e+1)
 	end
 end

 -- try protected_destructor directive
 do
 	local b,e = string.find(s, "^%s*TOLUA_PROTECTED_DESTRUCTOR%s*;?")
	if b then
		if self.set_protected_destructor then
	 		self:set_protected_destructor(true)
	 	end
 		return strsub(s, e+1)
 	end
 end

 -- try 'extern' keyword
 do
 	local b,e = string.find(s, "^%s*extern%s+")
 	if b then
		-- do nothing
 		return strsub(s, e+1)
 	end
 end
	
 -- try 'virtual' keyworkd
 do
 	local b,e = string.find(s, "^%s*virtual%s+")
 	if b then
 		methodisvirtual = true
 		return strsub(s, e+1)
 	end
 end

 -- try labels (public, private, etc)
 do
 	local b,e = string.find(s, "^%s*%w*%s*:[^:]")
 	if b then
 		return strsub(s, e) -- preserve the [^:]
 	end
 end

 -- try module
 do
  local b,e,name,body = strfind(s,"^%s*module%s%s*([_%w][_%w]*)%s*(%b{})%s*")
  if b then
   _curr_code = strsub(s,b,e)
   Module(name,body)
   return strsub(s,e+1)
  end
 end

 -- try namesapce
 do
  local b,e,name,body = strfind(s,"^%s*namespace%s%s*([_%w][_%w]*)%s*(%b{})%s*;?")
  if b then
   _curr_code = strsub(s,b,e)
   Namespace(name,body)
   return strsub(s,e+1)
  end
 end

 -- try define
 do
  local b,e,name = strfind(s,"^%s*#define%s%s*([^%s]*)[^\n]*\n%s*")
  if b then
   _curr_code = strsub(s,b,e)
   Define(name)
   return strsub(s,e+1)
  end
 end

 -- try enumerates

 do
  local b,e,name,body,varname = strfind(s,"^%s*enum%s+(%S*)%s*(%b{})%s*([^%s;]*)%s*;?%s*")
  if b then
   --error("#Sorry, declaration of enums and variables on the same statement is not supported.\nDeclare your variable separately (example: '"..name.." "..varname..";')")
   _curr_code = strsub(s,b,e)
   Enumerate(name,body,varname)
   return strsub(s,e+1)
  end
 end

-- do
--  local b,e,name,body = strfind(s,"^%s*enum%s+(%S*)%s*(%b{})%s*;?%s*")
--  if b then
--   _curr_code = strsub(s,b,e)
--   Enumerate(name,body)
--  return strsub(s,e+1)
--  end
-- end

 do
  local b,e,body,name = strfind(s,"^%s*typedef%s+enum[^{]*(%b{})%s*([%w_][^%s]*)%s*;%s*")
  if b then
   _curr_code = strsub(s,b,e)
   Enumerate(name,body)
   return strsub(s,e+1)
  end
 end

 -- try operator
 do
  local b,e,decl,kind,arg,const = strfind(s,"^%s*([_%w][_%w%s%*&:<>,]-%s+operator)%s*([^%s][^%s]*)%s*(%b())%s*(c?o?n?s?t?)%s*;%s*")
  if not b then
		 -- try inline
   b,e,decl,kind,arg,const = strfind(s,"^%s*([_%w][_%w%s%*&:<>,]-%s+operator)%s*([^%s][^%s]*)%s*(%b())%s*(c?o?n?s?t?)[%s\n]*%b{}%s*;?%s*")
  end
  if not b then
  	-- try cast operator
  	b,e,decl,kind,arg,const = strfind(s, "^%s*(operator)%s+([%w_:%d<>%*%&%s]+)%s*(%b())%s*(c?o?n?s?t?)");
  	if b then
  		local _,ie = string.find(s, "^%s*%b{}", e+1)
  		if ie then
  			e = ie
  		end
  	end
  end
  if b then
   _curr_code = strsub(s,b,e)
   Operator(decl,kind,arg,const)
   return strsub(s,e+1)
  end
 end

 -- try function
 do
  --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w])%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*")
  local b,e,decl,arg,const,virt = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)%s*(=?%s*0?)%s*;%s*")
  if not b then
  	-- try function with template
  	b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w]%b<>)%s*(%b())%s*(c?o?n?s?t?)%s*=?%s*0?%s*;%s*")
  end
  if not b then
   -- try a single letter function name
   b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?)%s*;%s*")
  end
  if b then
  	if virt and string.find(virt, "[=0]") then
  		if self.flags then
  			self.flags.pure_virtual = true
  		end
  	end
   _curr_code = strsub(s,b,e)
   Function(decl,arg,const)
   return strsub(s,e+1)
  end
 end

 -- try inline function
 do
  local b,e,decl,arg,const = strfind(s,"^%s*([^%(\n]+)%s*(%b())%s*(c?o?n?s?t?)[^;{]*%b{}%s*;?%s*")
  --local b,e,decl,arg,const = strfind(s,"^%s*([~_%w][_@%w%s%*&:<>]*[_%w>])%s*(%b())%s*(c?o?n?s?t?)[^;]*%b{}%s*;?%s*")
  if not b then
   -- try a single letter function name
   b,e,decl,arg,const = strfind(s,"^%s*([_%w])%s*(%b())%s*(c?o?n?s?t?).-%b{}%s*;?%s*")
  end
  if b then
   _curr_code = strsub(s,b,e)
   Function(decl,arg,const)
   return strsub(s,e+1)
  end
 end

 -- try class
 do
	 local b,e,name,base,body
		base = '' body = ''
		b,e,name = strfind(s,"^%s*class%s*([_%w][_%w@]*)%s*;")  -- dummy class
		if not b then
			b,e,name = strfind(s,"^%s*struct%s*([_%w][_%w@]*)%s*;")    -- dummy struct
			if not b then
				b,e,name,base,body = strfind(s,"^%s*class%s*([_%w][_%w@]*)%s*(.-)%s*(%b{})%s*;%s*")
				if not b then
					b,e,name,base,body = strfind(s,"^%s*struct%s*([_%w][_%w@]*)%s*(.-)%s*(%b{})%s*;%s*")
					if not b then
						b,e,name,base,body = strfind(s,"^%s*union%s*([_%w][_%w@]*)%s*(.-)%s*(%b{})%s*;%s*")
						if not b then
							base = ''
							b,e,body,name = strfind(s,"^%s*typedef%s%s*struct%s%s*[_%w]*%s*(%b{})%s*([_%w][_%w@]*)%s*;%s*")
						end
					end
				end
			end
		end
		if b then
			if base ~= '' then
				base = string.gsub(base, "^%s*:%s*", "")
				base = string.gsub(base, "%s*public%s*", "")
				base = split(base, ",")
				--local b,e
				--b,e,base = strfind(base,".-([_%w][_%w<>,:]*)$")
			else
				base = {}
			end
			_curr_code = strsub(s,b,e)
			Class(name,base,body)
			return strsub(s,e+1)
		end
	end

 -- try typedef
 do
  local b,e,types = strfind(s,"^%s*typedef%s%s*(.-)%s*;%s*")
  if b then
   _curr_code = strsub(s,b,e)
   Typedef(types)
   return strsub(s,e+1)
  end
 end

 -- try variable
 do
  local b,e,decl = strfind(s,"^%s*([_%w][_@%s%w%d%*&:<>,]*[_%w%d])%s*;%s*")
  if b then
   _curr_code = strsub(s,b,e)

	local list = split_c_tokens(decl, ",")
	Variable(list[1])
	if list.n > 1 then
		local _,_,type = strfind(list[1], "(.-)%s+([^%s]*)$");

		local i =2;
		while list[i] do
			Variable(type.." "..list[i])
			i=i+1
		end
	end
   --Variable(decl)
   return strsub(s,e+1)
  end
 end

	-- try string
 do
  local b,e,decl = strfind(s,"^%s*([_%w]?[_%s%w%d]-char%s+[_@%w%d]*%s*%[%s*%S+%s*%])%s*;%s*")
  if b then
   _curr_code = strsub(s,b,e)
   Variable(decl)
   return strsub(s,e+1)
  end
 end

 -- try array
 do
  local b,e,decl = strfind(s,"^%s*([_%w][][_@%s%w%d%*&:]*[]_%w%d])%s*;%s*")
  if b then
   _curr_code = strsub(s,b,e)
   Array(decl)
   return strsub(s,e+1)
  end
 end

 -- no matching
 if gsub(s,"%s%s*","") ~= "" then
  _curr_code = s
  error("#parse error")
 else
  return ""
 end

end

function classContainer:parse (s)

	self.curr_member_access = nil

 while s ~= '' do
  s = self:doparse(s)
  methodisvirtual = false
 end
end


-- property types

function get_property_type()

	return classContainer.curr:get_property_type()
end

function classContainer:set_property_type(ptype)
	ptype = string.gsub(ptype, "^%s*", "")
	ptype = string.gsub(ptype, "%s*$", "")

	self.property_type = ptype
end

function classContainer:get_property_type()
	return self.property_type or (self.parent and self.parent:get_property_type()) or "default"
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -