Change scripting engine from V8 to duktape

This commit is contained in:
David Capello 2015-06-19 13:06:47 -03:00
parent 401dd5362b
commit 699d60b03f
8 changed files with 44 additions and 76 deletions

3
.gitmodules vendored
View File

@ -7,3 +7,6 @@
[submodule "third_party/gtest"]
path = third_party/gtest
url = https://github.com/aseprite/gtest.git
[submodule "third_party/duktape"]
path = third_party/duktape
url = https://github.com/aseprite/duktape.git

View File

@ -111,6 +111,7 @@ set(PIXMAN_DIR ${CMAKE_SOURCE_DIR}/third_party/pixman)
set(SIMPLEINI_DIR ${CMAKE_SOURCE_DIR}/third_party/simpleini)
set(TINYXML_DIR ${CMAKE_SOURCE_DIR}/third_party/tinyxml)
set(ZLIB_DIR ${CMAKE_SOURCE_DIR}/third_party/zlib)
set(DUKTAPE_DIR ${CMAKE_SOURCE_DIR}/third_party/duktape)
# Search in the "cmake" directory for additional CMake modules.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
@ -157,6 +158,9 @@ else()
include_directories(${LIBPNG_DIR})
endif()
# Include duktape directory
include_directories(${DUKTAPE_DIR})
# Do not use MMX optimizations in PNG code
add_definitions(-DPNG_NO_MMX_CODE)

View File

@ -1,19 +0,0 @@
# ASEPRITE
# Copyright (C) 2001-2012 David Capello
find_path(V8_INCLUDE_DIR NAMES v8.h
HINTS "$ENV{V8_DIR}/include")
find_library(V8_BASE NAMES v8_base
HINTS "$ENV{V8_DIR}"
"$ENV{V8_DIR}/lib"
"$ENV{V8_DIR}/build/Release/lib")
find_library(V8_SNAPSHOT NAMES v8_snapshot
HINTS "$ENV{V8_DIR}"
"$ENV{V8_DIR}/lib"
"$ENV{V8_DIR}/build/Release/lib")
mark_as_advanced(V8_INCLUDE_DIR V8_BASE V8_SNAPSHOT)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(V8 DEFAULT_MSG V8_BASE V8_SNAPSHOT V8_INCLUDE_DIR)
set(V8_LIBRARIES ${V8_BASE} ${V8_SNAPSHOT})

View File

@ -1,18 +1,7 @@
# ASEPRITE
# Copyright (C) 2001-2013 David Capello
find_package(V8)
set(V8_FOUND ${V8_FOUND} PARENT_SCOPE)
set(V8_INCLUDE_DIR ${V8_INCLUDE_DIR} PARENT_SCOPE)
set(V8_LIBRARIES ${V8_LIBRARIES} PARENT_SCOPE)
if(V8_FOUND)
include_directories(${V8_INCLUDE_DIR})
add_definitions(-DHAVE_V8_LIBRARY)
else()
message(WARNING "V8 not found, compiling without JS scripting support")
endif()
# Copyright (C) 2001-2013, 2015 David Capello
add_library(scripting-lib
engine.cpp)
target_link_libraries(scripting-lib duktape)

View File

@ -7,11 +7,7 @@
#include "scripting/engine.h"
#ifdef HAVE_V8_LIBRARY
#include "scripting/engine_v8.h"
#else
#include "scripting/engine_none.h"
#endif
#include "scripting/engine_duktape.h"
namespace scripting {

View File

@ -1,38 +1,29 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#include "scripting/engine.h"
#include <v8.h>
using namespace v8;
class scripting::Engine::EngineImpl
{
public:
EngineImpl() { }
bool supportEval() const {
return true;
}
void eval(const std::string& scriptString) {
HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
Handle<String> source = String::New(scriptString.c_str());
Handle<Script> script = Script::Compile(source);
Handle<Value> result = script->Run();
context.Dispose();
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
}
};
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#include "scripting/engine.h"
#include <duktape.h>
class scripting::Engine::EngineImpl
{
public:
EngineImpl() { }
bool supportEval() const {
return true;
}
void eval(const std::string& scriptString) {
duk_context *ctx = duk_create_heap_default();
duk_eval_string(ctx, scriptString.c_str());
duk_pop(ctx);
printf("%s\n", duk_get_string(ctx, -1));
duk_destroy_heap(ctx);
}
};

View File

@ -55,3 +55,6 @@ if(NOT USE_SHARED_PIXMAN)
endif()
add_subdirectory(simpleini)
# Duktape
add_library(duktape duktape/duktape.c)

1
third_party/duktape vendored Submodule

@ -0,0 +1 @@
Subproject commit 90090c7f9277e192af58e1878aee24e5d9f48eaa