From 5665ac848da64db0ce43dbc3f3b731fc8988712b Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 6 May 2016 16:51:07 -0300 Subject: [PATCH] script: add className to Context::pushThis() --- src/app/script/sprite_class.cpp | 2 +- src/script/engine.cpp | 8 +++++++- src/script/engine.h | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/script/sprite_class.cpp b/src/app/script/sprite_class.cpp index 07aff91c1..ee8d33bce 100644 --- a/src/app/script/sprite_class.cpp +++ b/src/app/script/sprite_class.cpp @@ -45,7 +45,7 @@ script::result_t Sprite_ctor(script::ContextHandle handle) sprite.release(); doc->setContext(UIContext::instance()); - ctx.pushThis(unwrap_engine(ctx)->wrapSprite(doc.release())); + ctx.pushThis(unwrap_engine(ctx)->wrapSprite(doc.release()), "Sprite"); } return 0; } diff --git a/src/script/engine.cpp b/src/script/engine.cpp index eea3c587c..7d1588bf0 100644 --- a/src/script/engine.cpp +++ b/src/script/engine.cpp @@ -284,11 +284,17 @@ void Context::pushThis() duk_push_this(m_handle); } -void Context::pushThis(void* ptr) +void Context::pushThis(void* ptr, const char* className) { duk_push_this(m_handle); duk_push_pointer(m_handle, ptr); duk_put_prop_string(m_handle, -2, kPtrId); + + // TODO classes in modules isn't supported yet + duk_get_global_string(m_handle, className); + duk_get_prototype(m_handle, -1); + duk_set_prototype(m_handle, -3); + duk_pop_2(m_handle); } void Context::pushPointer(void* ptr) diff --git a/src/script/engine.h b/src/script/engine.h index fc6e2a515..451121c8a 100644 --- a/src/script/engine.h +++ b/src/script/engine.h @@ -94,7 +94,7 @@ namespace script { void pushUInt(unsigned int val); void pushString(const char* str); void pushThis(); - void pushThis(void* ptr); + void pushThis(void* ptr, const char* className); void pushPointer(void* ptr); index_t pushObject(); index_t pushObject(void* ptr, const char* className);