大佬教程收集整理的这篇文章主要介绍了自动生成类包含头文件,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/usr/bin/env lua ------------------------------------------------------------------------------- -- this LUA script is aim to generate include shutcut file in ./inc/ -- First,it will find all *.h and *.hpp files in current path. Then,find out -- all class which defined in head file. Next,build a file in ./inc/ which be -- named with class name. Last,write "#include "./<headfile>"" into that file. -- auth : Chunjun Li <[email protected]> -- date : 2013-10-02 ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -- get_class_list_in_file -- \berif find all class which is defined in head file,and return class name -- table. ------------------------------------------------------------------------------- function get_class_list_in_file(file_name) local class_list = {} local headfile = assert(io.open(file_name,"r")) while true do local line = headfile:read("*line") if line == nil then break end if String.find(line,"^class%s+") then if not String.find(line,"^class%s+%a[%w_]*%s*;$") then local _,_,class_name = String.find(line,"^class%s+(%a[%w_]*)") if class_name then table.insert(class_list,class_Name) end end end end headfile:close() return class_list end ------------------------------------------------------------------------------- -- build_class_include_file -- \berif build a file in ./inc/ and named as class name. then write C include -- statent inside. ------------------------------------------------------------------------------- function build_class_include_file(class_name,file_name) local context = "#include \"../" .. file_name .. "\"\n" local outfile = assert(io.open("inc/" .. class_name,"a")) outfile:write(context) outfile:close() end ------------------------------------------------------------------------------- -- do_file -- \berif find classes and build class include files in ./inc/ ------------------------------------------------------------------------------- function do_file(file_name) class_list = get_class_list_in_file(file_name) for _,class_name in pairs(class_list) do build_class_include_file(class_name,file_name) print(class_name .. " --> " .. file_name) end end ------------------------------------------------------------------------------- -- scan_head_files -- \berif find all head file and run do_file() each ------------------------------------------------------------------------------- function scan_head_files(path) local tmp_file_name = "head_file_list.tmp" local find_cmd = "find " .. path .. " -type f -name \"*.h\" -or -name \"*.hpp\" > " .. tmp_file_name os.execute "rm -rf ./inc" os.execute "mkdir ./inc" os.execute(find_cmd) local file = assert(io.open(tmp_file_name,"r")) while true do local line = file:read("*line") if line == nil then break end do_file(linE) end file:close() os.remove(tmp_file_name) end scan_head_files("./")
以上是大佬教程为你收集整理的自动生成类包含头文件全部内容,希望文章能够帮你解决自动生成类包含头文件所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。