本文整理汇总了Python中interpreter.Interpreter.getFunc方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.getFunc方法的具体用法?Python Interpreter.getFunc怎么用?Python Interpreter.getFunc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.getFunc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import getFunc [as 别名]
def main():
# excluding this programs name (argv[0]) and all arguments up to and
# and excluding the first "--" are c files to include
try:
c_code_files = argv[1:argv.index("--")]
except ValueError: # there might be no "--"
c_code_files = argv[1:]
if len(c_code_files) == 0:
raise Exception("You must provide at least one C source file")
state = State()
state.autoSetupSystemMacros()
state.autoSetupGlobalIncludeWrappers()
interpreter = Interpreter()
interpreter.register(state)
for cfile in c_code_files:
state = parse(cfile, state)
main_func = interpreter.getFunc("main")
if len(main_func.C_argTypes) == 0:
return_code = interpreter.runFunc("main", return_as_ctype=False)
else:
# if the main() function doesn't have zero arguments, it
# should have the standard two, (int argc0, char **argv0)
assert(len(main_func.C_argTypes) == 2)
# first c file is program name and first argument
arguments_to_c_prog = [c_code_files[0]]
try: # append everything after the "--" as c program arguments
arguments_to_c_prog += argv[argv.index("--")+1:]
except: ValueError
# return_as_ctype=False as we're expecting a simple int or None for void
return_code = interpreter.runFunc(
"main",
len(arguments_to_c_prog), arguments_to_c_prog,
return_as_ctype=False)
if isinstance(return_code, int):
exit(return_code)