Previous: Using Flusspferd from C++
Let's begin with a very simple program, a version of "Hello World".
#include <flusspferd.hpp> #include <iostream> #include <ostream> int main() { // Create and use a context, needed to be able to use Flusspferd. flusspferd::current_context_scope context_scope( flusspferd::context::create()); // Create a new string and protect it from the garbage collector by making // it a root string. flusspferd::root_string str("Hello, World!\n"); // Demonstrate that str will not be garbage collected, by calling the // garbage collector. // Note that there is no other reason to call the garbage collector here. flusspferd::gc(); // Set a property on the global object. Effectively, this creates a global // variable "str" with the contents of str. flusspferd::global().set_property("str", str); // Print str on std::cout - but first, replace "World" by "Flusspferd". std::cout << flusspferd::evaluate("str.replace('World', 'Flusspferd')"); }
help/examples/first_program.cpp.In order to use Flusspferd, we need to create a context and make it the current context, which flusspferd::current_context_scope does as long it is in scope. You can use flusspferd::current_context_scope in multiple nested scopes.
Now that you've got a (very) simple project that uses Flusspferd, its time to compile it.
We assume that you have already installed Flusspferd. To use it in your project, you can use pkg-config, like this:
$ g++ $(pkg-config --cflags --libs flusspferd) myfile.cpp
If you use a build system, you can use its pkg-config integration.
Let's go with the simple method of shelling out to pkg-config for now. We don't recommend that you use this method for any serious development, but it has the advantage of being easy and quick.
$ g++ $(pkg-config --cflags --libs flusspferd) -o first_program first_program.cpp >/dev/null $ ./first_programm Hello, Flusspferd! $
If you see the output "Hello, Flusspferd!" and just get a shell back, then everything worked. If either of the above commands produces any different output, then something went wrong in the install proccess and most likely a required file couldn't be found.
Next: Values and objects.
Contact us at team -AT- flusspferd -DOT- org or as described on our homepage.
Generated on Thu Feb 4 23:05:12 2010 for Flusspferd by
1.6.1