Skip to content

Instantly share code, notes, and snippets.

Created June 12, 2014 08:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/58c2395eef9daf6be7e8 to your computer and use it in GitHub Desktop.
Save anonymous/58c2395eef9daf6be7e8 to your computer and use it in GitHub Desktop.
dart_sfml test
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "include/dart_api.h"
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <SFML/Window.hpp>
Dart_NativeFunction ResolveName(Dart_Handle name,
int argc,
bool* auto_setup_scope);
DART_EXPORT Dart_Handle dart_sfml_Init(Dart_Handle parent_library) {
if (Dart_IsError(parent_library)) {
return parent_library;
}
Dart_Handle result_code = Dart_SetNativeResolver(parent_library, ResolveName, NULL);
if (Dart_IsError(result_code)) {
return result_code;
}
return Dart_Null();
}
Dart_Handle HandleError(Dart_Handle handle) {
if (Dart_IsError(handle)) {
Dart_PropagateError(handle);
}
return handle;
}
void CreateWindow(Dart_NativeArguments arguments) {
Dart_EnterScope();
sf::Window window(sf::VideoMode(600, 400), "testwindow");
Dart_ExitScope();
}
struct FunctionLookup {
const char* name;
Dart_NativeFunction function;
};
FunctionLookup function_list[] = {
{"CreateWindow", CreateWindow}
};
Dart_NativeFunction ResolveName(Dart_Handle name,
int argc,
bool* auto_setup_scope) {
if (!Dart_IsString(name)) {
return NULL;
}
Dart_NativeFunction result = NULL;
if (auto_setup_scope == NULL) {
return NULL;
}
Dart_EnterScope();
const char* cname;
HandleError(Dart_StringToCString(name, &cname));
for (int i=0; function_list[i].name != NULL; ++i) {
if (strcmp(function_list[i].name, cname) == 0) {
*auto_setup_scope = true;
result = function_list[i].function;
break;
}
}
if (result != NULL) {
Dart_ExitScope();
return result;
}
Dart_ExitScope();
return result;
}
library sfml;
import 'dart-ext:dart_sfml';
void createWindow(String name, int width, int height) native 'CreateWindow';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment