📄 class.lua
字号:
-- tolua: class class-- Written by Waldemar Celes-- TeCGraf/PUC-Rio-- Jul 1998-- $Id: $-- This code is free software; you can redistribute it and/or modify it.-- The software provided hereunder is on an "as is" basis, and-- the author has no obligation to provide maintenance, support, updates,-- enhancements, or modifications.-- Class class-- Represents a class definition.-- Stores the following fields:-- name = class name-- base = class base, if any (only single inheritance is supported)-- {i} = list of membersclassClass = { classtype = 'class', name = '', base = '', type = '', btype = '', ctype = '',}classClass.__index = classClasssetmetatable(classClass,classContainer)-- register classfunction classClass:register () push(self) output('#ifdef __cplusplus\n') if _collect[self.type] then output(' tolua_cclass(tolua_S,"'..self.lname..'","'..self.type..'","'..self.btype..'",tolua_collect_'.._collect[self.type]..');') else output(' tolua_cclass(tolua_S,"'..self.lname..'","'..self.type..'","'..self.btype..'",0);') end output('#else\n') output(' tolua_cclass(tolua_S,"'..self.lname..'","'..self.type..'","'..self.btype..'",tolua_collect);') output('#endif\n') output(' tolua_beginmodule(tolua_S,"'..self.lname..'");') local i=1 while self[i] do self[i]:register() i = i+1 end output(' tolua_endmodule(tolua_S);') pop()end-- return collection requirementfunction classClass:requirecollection (t) push(self) local i=1 while self[i] do self[i]:requirecollection(t) i = i+1 end pop() -- TODO --t[self.type] = gsub(self.type,"::","_") return trueend-- output tagsfunction classClass:decltype () push(self) self.type = regtype(self.name) self.btype = typevar(self.base) self.ctype = 'const '..self.type local i=1 while self[i] do self[i]:decltype() i = i+1 end pop()end-- Print methodfunction classClass:print (ident,close) print(ident.."Class{") print(ident.." name = '"..self.name.."',") print(ident.." base = '"..self.base.."';") print(ident.." lname = '"..self.lname.."',") print(ident.." type = '"..self.type.."',") print(ident.." btype = '"..self.btype.."',") print(ident.." ctype = '"..self.ctype.."',") local i=1 while self[i] do self[i]:print(ident.." ",",") i = i+1 end print(ident.."}"..close)end-- Internal constructorfunction _Class (t) setmetatable(t,classClass) t:buildnames() append(t) return tend-- Constructor-- Expects the name, the base and the body of the class.function Class (n,p,b) local c = _Class(_Container{name=n, base=p}) push(c) c:parse(strsub(b,2,strlen(b)-1)) -- eliminate braces pop()end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -