Skip to content

Instantly share code, notes, and snippets.

@bithavoc
Created January 21, 2015 22:58
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 bithavoc/4030fbf9080782d76575 to your computer and use it in GitHub Desktop.
Save bithavoc/4030fbf9080782d76575 to your computer and use it in GitHub Desktop.
da fuq is rocka lang
// 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