Skip to content

Instantly share code, notes, and snippets.

@waterlink
Created Dec 29, 2014
Embed
What would you like to do?
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