Created
January 21, 2015 22:58
-
-
Save bithavoc/4030fbf9080782d76575 to your computer and use it in GitHub Desktop.
da fuq is rocka lang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example of Rocka: An interpreted, duck-typed, Object-Oriented and Functional programming language | |
// Example source code of Rocka | |
// #$RKROOT/lib/standard/io.rk | |
// | |
namespace Standard.IO; | |
// defined in standard_io.cpp | |
extern public print(msg string) bool; | |
namespace RockaExample; | |
import Standard.IO; | |
class EntryPoint { | |
main -> void { | |
println("Hello World".nice()); | |
println("Here are come characters: "); | |
printChars("foo"); | |
} | |
nice(text string) -> string { | |
return text.Upper(); | |
} | |
printChars(s string) { | |
s.for_each(print) | |
} | |
} | |
// | |
// standard_io.cpp | |
// | |
std::shared_ptr<rocka::Vm> vm = std::make_shared<rocka::Vm>(); | |
vm->land()->namespace("Standard.IO")->registerFunction("print", [] (std::shared_ptr<rocka::VM> vm, const rocka::Value& value, rocka::Value& result) { | |
try { | |
std::cout << value.at(0).as<std::string>() << std::endl; | |
} catch(const exception& ex) { | |
result.setBool(false) | |
return | |
} | |
result.setBool(true) | |
}); | |
// compile with: cpp standard_io.cpp -lrocka -o standard_io.a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment