Skip to content

Instantly share code, notes, and snippets.

@waterlink
Created December 29, 2014 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waterlink/e00f4a5ee2940a69a1d2 to your computer and use it in GitHub Desktop.
Save waterlink/e00f4a5ee2940a69a1d2 to your computer and use it in GitHub Desktop.
Hello World example in ruby2cpp annotated ruby. Ready to be converted to c++.
# @ruby2cpp: std
class Hello
# @ruby2cpp: annotate(String -> void)
def initialize(greeting)
# @ruby2cpp: annotate(String)
@greeting = greeting
end
# @ruby2cpp: annotate(String -> void)
def greet(name)
puts("debug: Hello#greet :: got in")
puts("%s, %s!" % [@greeting, name])
end
# @ruby2cpp: annotate(-> void)
def anonymous_greet
puts("%s!" % @greeting)
end
end
# @ruby2cpp: annotate(String, String -> void)
def greet(greeting, name)
# @ruby2cpp: annotate(Hello)
hello = Hello.new(greeting)
hello.greet(name)
# @ruby2cpp: annotate(bool)
done = true
end
# @ruby2cpp: annotate(-> int)
def main
# @ruby2cpp: annotate(String)
greeting = "Hello"
# @ruby2cpp: annotate(String)
name = "World"
greet(greeting, name)
# @ruby2cpp: annotate(int)
exit_code = 0
end
# @ruby2cpp: entry_point
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment