From: Alexis Laferrière Date: Thu, 20 Aug 2015 20:02:16 +0000 (-0400) Subject: contrib/objcwrapper: add the -o option to specify the output file X-Git-Tag: v0.7.8~76^2~4 X-Git-Url: http://nitlanguage.org contrib/objcwrapper: add the -o option to specify the output file Signed-off-by: Alexis Laferrière --- diff --git a/contrib/objcwrapper/src/objc_generator.nit b/contrib/objcwrapper/src/objc_generator.nit index 673e306..3b50721 100644 --- a/contrib/objcwrapper/src/objc_generator.nit +++ b/contrib/objcwrapper/src/objc_generator.nit @@ -15,8 +15,15 @@ # Code generation module objc_generator +import opts + import objc_model +redef class Sys + # Path to the output file + var opt_output = new OptionString("Output file", "-o") +end + class CodeGenerator # Merge the calls to `alloc` and `init...` in a single constructor? # @@ -34,11 +41,25 @@ class CodeGenerator var init_with_alloc = true is writable fun generator(classes: Array[nullable ObjcClass]) do + # Open specified path or stdin + var file + var path = opt_output.value + if path != null then + if path.file_extension != "nit" then + print_error "Warning: output file path does not end with '.nit'" + end + + file = new FileWriter.open(path) + else + file = stdout + end + + # Generate code for classe in classes do - var file = new FileWriter.open(classe.name + ".nit") nit_class_generator(classe, file, init_with_alloc) - file.close end + + if path != null then file.close end fun type_convertor(type_word: String): String do