cpgf library documentation

Built-in meta data for SFML -- Simple and Fast Multimedia Library in C++ cpgf library


The meta data for SFML is a collection of meta data to represent for SFML library.
Now the supported SFML version is 1.6.

With the meta data, it's a piece of cake to use SFML in Lua or Javascript language.

Screenshot of the demo using SFML in Google V8 Javascript script

Can't wait to experiment the SFML binding? Below is a piece of real Javascript code snippet that using SFML! To see more code, including Lua code, see samples/sfml/ in the library package.

    // Create the window of the application
    var App = new sfml.RenderWindow(new sfml.VideoMode(800, 600, 32), "SFML Pong -- cpgf SFML binding demo -- V8 Javascript");
    // Load the sounds used in the game
    var BallSoundBuffer = new sfml.SoundBuffer();
    	return sfml.EXIT_FAILURE;
    var BallSound = new sfml.Sound(BallSoundBuffer);
    // Load the images used in the game
    var BackgroundImage = new sfml.Image();
    var LeftPaddleImage = new sfml.Image;
    var RightPaddleImage = new sfml.Image();
    var BallImage = new sfml.Image();
    if (!BackgroundImage.LoadFromFile("datas/pong/background.jpg")    ||
    	!LeftPaddleImage.LoadFromFile("datas/pong/paddle_left.png")   ||
    	!RightPaddleImage.LoadFromFile("datas/pong/paddle_right.png") ||
    	return sfml.EXIT_FAILURE;

Build meta data

The meta data for SFML library is automatically generated by the tool metagen.
The header files are in folder include/cpgf/metadata/sfml
The source files are in folder src/metadata/sfml

To use the meta data, you need to link to all meta_sfml_*.cpp files in source folder.
To auto register the meta data to global namespace, link to register_meta_sfml.cpp. SFML will be registered to “sfml” namespace.
If you don't want to register the meta data to global, just call function registerMain_sfml with the desired meta define.
You can read the code in register_meta_sfml.cpp to see how it works.

The only things that are not supported by meta data
The only unsupported feature is that we can't use SFML Thread class in script binding (but we can use the meta data in C++).
It's not useful though there is meta data.
The reason is, currently both V8 Javascript and Lua binding doesn't support multiple threading yet.