script: add className to Context::pushThis()

This commit is contained in:
David Capello 2016-05-06 16:51:07 -03:00
parent af7c6e0fa9
commit 5665ac848d
3 changed files with 9 additions and 3 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -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);