Skip to content

Instantly share code, notes, and snippets.

@beakr
Last active December 27, 2015 06:29
Show Gist options
  • Save beakr/7281703 to your computer and use it in GitHub Desktop.
Save beakr/7281703 to your computer and use it in GitHub Desktop.
//
// librib -- fast, cross-platform game engine in Coffeescript
//
// Copyright (c) 2013 Christopher Clarke
// Please see attached LICENSE file for your distrobution.
//
#include "Scripter.hh"
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
namespace rib
{
namespace scripter
{
void Run(std::string& f, bool debugVal)
{
// Read contents of file given to a std::string.
std::ifstream ifs(f.c_str());
std::stringstream sstr;
sstr << ifs.rdbuf();
std::string code = sstr.str();
// Compile script.
v8::Handle<v8::String> v8Code = v8::String::New(code.c_str());
v8::Handle<v8::Script> script = v8::Script::Compile(v8Code);
// If we're debugging, we definitely want to print the ASCII
// output of the compiled script.
if (debugVal)
{
v8::Handle<v8::Value> output = script->Run();
v8::String::AsciiValue outStr(output);
printf("%s\n", *outStr);
} else {
script->Run();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment