Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

Commit

Permalink
[WIP] Converting the bindings to WebIDL
Browse files Browse the repository at this point in the history
  • Loading branch information
4ian committed May 20, 2015
1 parent ccd4bf3 commit e654ec3
Show file tree
Hide file tree
Showing 22 changed files with 1,093 additions and 1,343 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
/node_modules
/node_modules
Bindings/parser.out
Bindings/WebIDLGrammar.pkl
.cpp.old
96 changes: 96 additions & 0 deletions Bindings/Bindings.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* IDL file for GDevelop classes bindings.
*
* Notes:
*
* WRAPPED_* functions are declared as such to allow the Wrapper.cpp
* file to use a macro to do special work on it.
* These functions are renamed in the final .js file (so that
* `WRAPPED_set` become `set` for example).
*/

interface ProjectHelper {
[Ref] Project STATIC_CreateNewGDJSProject();
void STATIC_InitializePlatforms();
};

interface VectorString {
void push_back([Const] DOMString str);
void resize(long size);
long size();
[Const, Ref] DOMString at(long index);
void WRAPPED_set(long index, [Const, Ref] DOMString str);
void clear();
};

interface Project {
void Project();
void SetName([Const] DOMString name);
[Const, Ref] DOMString GetName();
void SetAuthor([Const] DOMString name);
[Const, Ref] DOMString GetAuthor();
void SetProjectFile([Const] DOMString file);
[Const, Ref] DOMString GetProjectFile();
void SetDefaultWidth(long width);
long GetMainWindowDefaultWidth();
void SetDefaultHeight(long height);
long GetMainWindowDefaultHeight();
long GetMaximumFPS();
void SetMaximumFPS(long fps);
long GetMinimumFPS();
void SetMinimumFPS(long fps);
[Const, Ref] VectorString GetUsedExtensions();

boolean HasLayoutNamed([Const] DOMString name);
[Ref] Layout InsertNewLayout([Const] DOMString name, long position);
[Ref] Layout GetLayout([Const] DOMString name);
};

interface Layout {
void Layout();

void SetName([Const] DOMString name);
[Const, Ref] DOMString GetName();
};



interface InitialInstance {
void InitialInstance();

void SetObjectName([Const] DOMString name);
[Const, Ref] DOMString GetObjectName();

float GetX();
void SetX(float x);
float GetY();
void SetY(float y);
float GetAngle();
void SetAngle(float angle);
long GetZOrder();
void SetZOrder(long zOrder);
[Const, Ref] DOMString GetLayer();
void SetLayer([Const] DOMString layer);
};

interface InitialInstancesContainer {
void InitialInstancesContainer();

long GetInstancesCount();

void IterateOverInstances([Ref] InitialInstanceFunctor func);
void IterateOverInstancesWithZOrdering([Ref] InitialInstanceFunctor func, DOMString layer);
void RemoveAllInstancesOnLayer(DOMString layer);
boolean SomeInstancesAreOnLayer(DOMString layer);

[Ref] InitialInstance InsertNewInitialInstance();
};

interface InitialInstanceFunctor {};
interface InitialInstanceJSFunctorWrapper {};
[JSImplementation="InitialInstanceJSFunctorWrapper"]
interface InitialInstanceJSFunctor {
void InitialInstanceJSFunctor();

void invoke(InitialInstance instance);
};
48 changes: 48 additions & 0 deletions Bindings/ProjectHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "GDCore/PlatformDefinition/Project.h"
#include "GDCore/PlatformDefinition/Layout.h"
#include "GDCore/PlatformDefinition/Project.h"
#include "GDCore/PlatformDefinition/Platform.h"
#include "GDCore/IDE/PlatformManager.h"
#include "GDCore/TinyXml/tinyxml.h"
#include "GDCpp/CppPlatform.h"
#include "GDCore/PlatformDefinition/Platform.h"
#include "GDCore/PlatformDefinition/Platform.h"
#include "GDJS/JsPlatform.h"
#include "GDCore/PlatformDefinition/InitialInstancesContainer.h"

using namespace gdjs;
using namespace gd;

/**
* \brief A class providing helper functions related to projects.
*/
class ProjectHelper {
public:
static gd::Project & CreateNewGDJSProject()
{
Project * project = new Project;
project->AddPlatform(JsPlatform::Get());

return *project;
}

/**
* \brief Initialize the JS platform.
*/
static void InitializePlatforms()
{
static bool initialized = false;
if (initialized) {
std::cout << "ERROR: You're calling initializePlatforms again, but initialization was already done!" << std::endl;
return;
}

initialized = true;
std::cout << "Initializing GDJS platform" << std::endl;
{
std::shared_ptr<gd::Platform> platform(&JsPlatform::Get());
gd::PlatformManager::Get()->AddPlatform(platform);
}
std::cout << "Platform initialization ended." << std::endl;
}
};
33 changes: 33 additions & 0 deletions Bindings/Wrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <string>
#include <GDCore/PlatformDefinition/Project.h>
#include <GDCore/PlatformDefinition/Layout.h>
#include <GDCore/PlatformDefinition/InitialInstance.h>
#include <GDCore/PlatformDefinition/InitialInstancesContainer.h>
#include "ProjectHelper.h"

class InitialInstanceJSFunctorWrapper : public gd::InitialInstanceFunctor {
public:
InitialInstanceJSFunctorWrapper() {};

virtual void operator()(gd::InitialInstance * instance) {
invoke(instance);
};

virtual void invoke(gd::InitialInstance * instance) {
};
};

//Declares typedef for std::vector
typedef std::vector<std::string> VectorString;

//Customize some functions implementation thanks to WRAPPED_* macros
//The original names will be reconstructed in the js file (see postjs.js)
#define WRAPPED_set(a, b) at(a) = b
#define STATIC_CreateNewGDJSProject CreateNewGDJSProject
#define STATIC_InitializePlatforms InitializePlatforms

// We don't use prefix in .idl file to workaround a webidl_binder.py bug
// that can't find in its list of interfaces a class which has a prefix.
using namespace gd;
using namespace std;
#include "glue.cpp"
Loading

0 comments on commit e654ec3

Please sign in to comment.