Permalink
Browse files

add String#main? & String#if_main:else:

  • Loading branch information...
1 parent 593796d commit c3ea0fd16e3f3dc6a2e7730d14fadda772cac3df @bakkdoor committed Jun 30, 2012
Showing with 22 additions and 8 deletions.
  1. +1 −7 lib/argv.fy
  2. +1 −1 lib/compiler.fy
  3. +20 −0 lib/string.fy
View
@@ -38,10 +38,4 @@ def ARGV for_options: op_names do: block {
return true
}
}
-}
-
-def ARGV main?: filename {
- if: (ARGV[0]) then: {
- File expand_path: (ARGV[0]) . == filename
- }
-}
+}
View
@@ -8,7 +8,7 @@ require: "compiler/ast"
require: "parser"
-if: (ARGV main?: __FILE__) then: {
+__FILE__ if_main: {
require: "compiler/command"
Fancy Compiler Command run: (ARGV rest)
}
View
@@ -212,4 +212,24 @@ class String {
grep: /\n/ . size > 0
}
+
+ def main? {
+ """
+ @return @true if @self is the filename of the script that got executed initially.
+ """
+
+ File expand_path: (ARGV[0] to_s) == self
+ }
+
+ def if_main: main_block else: else_block ({}) {
+ """
+ @main_block @Block@ to be run if @String#:main?@ returns true.
+ @else_block @Block@ to be called otherwise.
+
+ Same as:
+ if: main? then: else_block else: else_block
+ """
+
+ if: main? then: main_block else: else_block
+ }
}

0 comments on commit c3ea0fd

Please sign in to comment.