コード例 #1
0
    def _build_file(self, luafiles):
        # 添加文件头
        llbc_file_path = op.join(Cfg.getscriptpath(), 'llbc.lua')
        f = open(llbc_file_path, 'wb')
        f.write('--[[\n')
        f.write('@file    llbc.lua\n')
        f.write('@author  {0}\n'.format(Cfg.getauthor()))
        f.write('@version {0}\n'.format(Cfg.getver()))
        f.write('@date    ----/--/--\n')
        f.write('\n')
        f.write('@brief   llbc lua wrap library(lullbc)\n')
        f.write('--]]\n\n')

        # 整合所有脚本
        for luafile in luafiles:
            with open(luafile, 'r') as lf:
                f.write('-- ******** SCRIPT: {0} ********\n'.format(
                    luafile[len(self._script_path) + 1:]).replace('\\', '/'))
                f.write(lf.read())
                f.write('\n\n')

        # 最后返回lib table
        f.write('\n')
        f.write('-- return library\n')
        f.write('return llbc\n')

        # 关闭文件
        f.close()
コード例 #2
0
ファイル: py_integrator_builder.py プロジェクト: gustars/llbc
    def build():
        """生成"""
        # Generate file head.
        imp = Cfg.getprojname().upper()
        cpp_file_path = op.join(Cfg.getcodepath(), 'pyllbc_scripts.h')
        cpp_file = CppFile(cpp_file_path, author=Cfg.getauthor(), ver=Cfg.getver(), include_macro_prefix=imp)
        cpp_file.addincl('pyllbc/common/LibHeader.h')
        cpp_file.addincl('pyllbc/common/ScriptIntegrator.h')

        # Generate constructor/destructor.
        class_name = 'pyllbc_Scripts'
        ctor = CppFun(class_name, rtn='', visit=CppVisit(CppVisit.PUBLIC))
        for root, dirs, files in os.walk(Cfg.getscriptpath()):
            for f in files:
                fpath = op.join(root, f)
                if '.svn' in fpath:
                    continue
                elif op.splitext(fpath)[1].lower() != '.py':
                    continue

                script_cnt = PyIntegratorBuilder.__transfer_to_cpp_str(fpath)
                ctor.addstmt('_scripts.insert(::std::make_pair("{0}", new ::pyllbc_ScriptIntegrator({1})));'
                             .format(op.basename(fpath), script_cnt))

        dtor = CppFun('~{0}'.format(class_name), rtn='', visit=CppVisit(CppVisit.PUBLIC))
        dtor.addstmt('LLBC_STLHelper::DeleteContainer(_scripts);')

        clazz = CppClass(class_name)
        clazz.addmethod(ctor)
        clazz.addmethod(dtor)

        # Generate integrate method.
        integrate_meth = CppFun('Integrate', rtn='int', visit=CppVisit(CppVisit.PUBLIC))
        integrate_meth.addstmt("for (::std::map<LLBC_String, "
                               "::pyllbc_ScriptIntegrator *>::iterator it = _scripts.begin();")
        integrate_meth.addstmt('     it != _scripts.end();')
        integrate_meth.addstmt('     it++)')
        integrate_meth.addstmt('    if (it->second->Integrate() != LLBC_OK)')
        integrate_meth.addstmt('        return LLBC_FAILED;')
        integrate_meth.addstmt('')
        integrate_meth.addstmt('return LLBC_OK;')
        clazz.addmethod(integrate_meth)

        # Generate data member.
        data_mem = CppData('::std::map<LLBC_String, ::pyllbc_ScriptIntegrator *>',
                           '_scripts',
                           visit=CppVisit(CppVisit.PRIVATE))
        clazz.adddata(data_mem)

        cpp_file.addcls(clazz)
        cpp_file.adddef('pyllbc_s_Scripts LLBC_Singleton<{0}, LLBC_DummyLock>::Instance()'.format(class_name))

        cpp_file.build()
コード例 #3
0
ファイル: lu_postbuild.py プロジェクト: zhouyanlt/llbc
def main():
    # 复制llbc.lua到目标目录
    target_path = sys.argv[3]
    is_debug = sys.argv[2].upper() == 'DEBUG' or False
    src = op.join(Cfg.getscriptpath(), 'llbc.lua')
    if not is_debug:
        target = op.join(target_path, 'llbc.lua')
    else:
        target = op.join(target_path, 'llbc_debug.lua')

    print 'Copy [{0}] to [{1}]...'.format(src, target)
    shutil.move(src, target)

    print 'Done!'
コード例 #4
0
ファイル: lu_script_integrator.py プロジェクト: gustars/llbc
    def _build_file(self, luafiles):
        # 添加文件头
        llbc_file_path = op.join(Cfg.getscriptpath(), 'llbc.lua')
        f = open(llbc_file_path, 'wb')
        f.write(Cfg.getlicensehead() + '\n')

        # 整合所有脚本
        for luafile in luafiles:
            with open(luafile, 'r') as lf:
                f.write('-- ******** SCRIPT: {0} ********\n'.format(
                    luafile[len(self._script_path) + 1:]).replace('\\', '/'))
                f.write(lf.read())
                f.write('\n\n')

        # 最后返回lib table
        f.write('\n')
        f.write('-- return library\n')
        f.write('return llbc\n')

        # 关闭文件
        f.close()
コード例 #5
0
 def __init__(self, debug):
     self._debug = debug
     self._script_path = Cfg.getscriptpath()