本文整理汇总了C++中JObject类的典型用法代码示例。如果您正苦于以下问题:C++ JObject类的具体用法?C++ JObject怎么用?C++ JObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: it
void PhysObject::DrawBounds()
{
JObjectIterator it( this );
++it;
while (it)
{
JObject* pObj = *it;
if (!pObj->IsDrawBounds())
{
pObj->DrawBounds();
}
++it;
}
} // PhysObject::DrawBounds
示例2: arguments
int JLuaServer::FnCall( lua_State* pLua )
{
if (lua_gettop( pLua ) < 2 || lua_gettop( pLua ) > 3)
{
rlog.err( "LUA: Incorrect command usage: <call>. "
"Function takes 2 to 3 arguments (object|objectName, funcName, [tag]), but %d is provided", lua_gettop( pLua ) );
lua_settop( pLua, 0 );
return 0;
}
JObject* pObj = NULL;
const char* pPath = lua_tostring( pLua, 1 );
if (pPath)
{
JLuaThread* pThread = reinterpret_cast<JLuaThread*>( pLua->userdata );
assert( pThread->m_pLua == pLua );
JObject* pRootObj = pThread->m_pRootObj;
pObj = g_pObjectServer->FindObject( pPath, NULL, pRootObj );
if (!pObj)
{
rlog.warn( "LUA: Method <call> refers to non-existing object: %s", pPath );
return NULL;
}
}
else
{
pObj = reinterpret_cast<JObject*>( lua_touserdata( pLua, 1 ) );
if (!pObj)
{
rlog.warn( "LUA: Trying to call <call> for the nil object" );
return NULL;
}
}
const char* pMethodName = lua_tostring( pLua, 2 );
int tag = -1;
if (lua_isnumber( pLua, 3 ))
{
tag = (int)lua_tonumber( pLua, 3 );
}
bool bRes = pObj->CallMethod( pMethodName, tag );
if (!bRes)
{
rlog.err( "LUA: Could not call method '%s' for object '%s' of type '%s'.",
pMethodName, pObj->GetName(), pObj->ClassName() );
}
return 0;
} // JLuaServer::FnCall
示例3: AfterClose
// Socket close result handler.
static void AfterClose(uv_handle_t* handle) {
HandleWrap* tcp_wrap = HandleWrap::FromHandle(handle);
IOTJS_ASSERT(tcp_wrap != NULL);
// tcp object.
JObject jtcp = tcp_wrap->jobject();
IOTJS_ASSERT(jtcp.IsObject());
// callback function.
JObject jcallback = jtcp.GetProperty("onclose");
if (jcallback.IsFunction()) {
MakeCallback(jcallback, JObject::Null(), JArgList::Empty());
}
}
示例4: JHANDLER_FUNCTION
JHANDLER_FUNCTION(Buffer, handler) {
IOTJS_ASSERT(handler.GetThis()->IsObject());
IOTJS_ASSERT(handler.GetArgLength() == 2);
IOTJS_ASSERT(handler.GetArg(0)->IsObject());
IOTJS_ASSERT(handler.GetArg(1)->IsNumber());
int length = handler.GetArg(1)->GetInt32();
JObject* jbuffer = handler.GetArg(0);
JObject* jbuiltin = handler.GetThis();
BufferWrap* buffer_wrap = new BufferWrap(*jbuffer, *jbuiltin, length);
IOTJS_ASSERT(buffer_wrap == (BufferWrap*)(jbuiltin->GetNative()));
IOTJS_ASSERT(buffer_wrap->buffer() != NULL);
return true;
}
示例5: compareTo
int JPoint::compareTo(const JObject& s) const {
if (className() != s.className())
return JObject::compareTo(s);
int result = y-((JPoint*)&s)->y;
if (!result) result = x-((JPoint*)&s)->x;
return result;
}
示例6: MakeStatObject
JObject MakeStatObject(uv_stat_t* statbuf) {
#define X(name) \
JObject name((int)statbuf->st_##name); \
X(dev)
X(mode)
X(nlink)
X(uid)
X(gid)
X(rdev)
#undef X
#define X(name) \
JObject name((double)statbuf->st_##name); \
X(blksize)
X(ino)
X(size)
X(blocks)
#undef X
Module* module = GetBuiltinModule(MODULE_FS);
JObject* fs = module->module;
JObject createStat = fs->GetProperty("createStat");
JArgList args(10);
args.Add(dev);
args.Add(mode);
args.Add(nlink);
args.Add(uid);
args.Add(gid);
args.Add(rdev);
args.Add(blksize);
args.Add(ino);
args.Add(size);
args.Add(blocks);
JResult jstat_res(createStat.Call(JObject::Null(), args));
IOTJS_ASSERT(jstat_res.IsOk());
return jstat_res.value();
}
示例7: InitFs
JObject* InitFs() {
Module* module = GetBuiltinModule(MODULE_FS);
JObject* fs = module->module;
if (fs == NULL) {
fs = new JObject();
fs->SetMethod("close", Close);
fs->SetMethod("open", Open);
fs->SetMethod("read", Read);
fs->SetMethod("write", Write);
fs->SetMethod("stat", Stat);
module->module = fs;
}
return fs;
}
示例8: lua_gettop
int JLuaServer::FnSetParent( lua_State* pLua )
{
if (lua_gettop( pLua ) != 2)
{
rlog.err( "LUA: Incorrect command usage: <setparent>. "
"Function takes 2 arguments, but %d is provided", lua_gettop( pLua ) );
lua_settop( pLua, 0 );
lua_pushnil( pLua );
return 1;
}
JObject* pParent = reinterpret_cast<JObject*>( lua_touserdata( pLua, 2 ) );
JObject* pObj = reinterpret_cast<JObject*>( lua_touserdata( pLua, 1 ) );
if (!pObj)
{
lua_pushnil( pLua );
return 0;
}
// set new parent for the object
JObject* pOldParent = pObj->GetParent();
if (pParent)
{
pParent->AddChild( pObj );
}
if (pOldParent)
{
pOldParent->RemoveChild( pObj );
}
pObj->SetParent( pParent );
return 0;
} // JLuaServer::FnSetParent
示例9: argument
int JLuaServer::FnChildren( lua_State* pLua )
{
if (lua_gettop( pLua ) != 1)
{
rlog.err( "LUA: Incorrect command usage: <children>. "
"Function takes 1 argument (<objectRef>|<objectName>), but %d is provided", lua_gettop( pLua ) );
lua_settop( pLua, 0 );
lua_pushnil( pLua );
return 1;
}
JObject* pObj = NULL;
const char* pPath = lua_tostring( pLua, -1 );
if (pPath)
{
JLuaThread* pThread = reinterpret_cast<JLuaThread*>( pLua->userdata );
assert( pThread->m_pLua == pLua );
JObject* pRootObj = pThread->m_pRootObj;
pObj = g_pObjectServer->FindObject( pPath, NULL, pRootObj );
}
else
{
pObj = reinterpret_cast<JObject*>( lua_touserdata( pLua, -1 ) );
}
if (!pObj)
{
lua_pushnil( pLua );
return 1;
}
// return table with children
int nCh = pObj->GetNChildren();
lua_createtable( pLua, nCh, 0 );
lua_newtable( pLua );
for (int i = 0; i < nCh; i++)
{
// key
lua_pushnumber( pLua, i + 1 );
// value (child pointer)
lua_pushlightuserdata( pLua, pObj->GetChild( i ) );
lua_settable( pLua, -3 );
}
return 1;
} // JLuaServer::FnChildren
示例10: SetProperty
void JObject::SetProperty(const char* name, const JObject& val) {
IOTJS_ASSERT(IsObject());
JRawValueType v = val.raw_value();
bool is_ok = jerry_api_set_object_field_value(
_obj_val.v_object,
reinterpret_cast<const jerry_api_char_t*>(name),
&v);
IOTJS_ASSERT(is_ok);
}
示例11: compareTo
int JThread::compareTo(const JObject& s) const {
if (className() != s.className())
return JObject::compareTo(s);
return id-((JThread*)&s)->id;
}
示例12: MakeStatObject
JObject MakeStatObject(uv_stat_t* statbuf) {
Module* module = GetBuiltinModule(MODULE_FS);
IOTJS_ASSERT(module != NULL);
JObject* fs = module->module;
IOTJS_ASSERT(fs != NULL);
JObject createStat = fs->GetProperty("_createStat");
IOTJS_ASSERT(createStat.IsFunction());
JObject jstat;
#define X(statobj, name) \
JObject name((int32_t)statbuf->st_##name); \
statobj.SetProperty(#name, name); \
X(jstat, dev)
X(jstat, mode)
X(jstat, nlink)
X(jstat, uid)
X(jstat, gid)
X(jstat, rdev)
#undef X
#define X(statobj, name) \
JObject name((double)statbuf->st_##name); \
statobj.SetProperty(#name, name); \
X(jstat, blksize)
X(jstat, ino)
X(jstat, size)
X(jstat, blocks)
#undef X
JArgList jargs(1);
jargs.Add(jstat);
JResult jstat_res(createStat.Call(JObject::Null(), jargs));
IOTJS_ASSERT(jstat_res.IsOk());
return jstat_res.value();
}
示例13: After
static void After(uv_fs_t* req) {
FsReqWrap* req_wrap = static_cast<FsReqWrap*>(req->data);
IOTJS_ASSERT(req_wrap != NULL);
IOTJS_ASSERT(req_wrap->data() == req);
JObject cb = req_wrap->jcallback();
IOTJS_ASSERT(cb.IsFunction());
JArgList jarg(2);
if (req->result < 0) {
JObject jerror(CreateUVException(req->result, "open"));
jarg.Add(jerror);
} else {
jarg.Add(JObject::Null());
switch (req->fs_type) {
case UV_FS_CLOSE:
{
break;
}
case UV_FS_OPEN:
case UV_FS_READ:
case UV_FS_WRITE:
{
JObject arg1(static_cast<int>(req->result));
jarg.Add(arg1);
break;
}
case UV_FS_STAT: {
uv_stat_t s = (req->statbuf);
JObject ret(MakeStatObject(&s));
jarg.Add(ret);
break;
}
default:
jarg.Add(JObject::Null());
}
}
JObject res = MakeCallback(cb, JObject::Null(), jarg);
uv_fs_req_cleanup(req);
delete req_wrap;
}
示例14: compareTo
int JFont::compareTo(const JObject& s) const {
if (className() != s.className())
return JObject::compareTo(s);
JFont &obj = *(JFont*)&s;
int result = name.compareTo(obj.name);
if (!result) {
result = style-obj.style;
if (!result) result = size-obj.size;
}
return result;
}
示例15: AfterConnect
// Connection request result handler.
static void AfterConnect(uv_connect_t* req, int status) {
ConnectReqWrap* req_wrap = reinterpret_cast<ConnectReqWrap*>(req->data);
TcpWrap* tcp_wrap = reinterpret_cast<TcpWrap*>(req->handle->data);
IOTJS_ASSERT(req_wrap != NULL);
IOTJS_ASSERT(tcp_wrap != NULL);
// Take callback function object.
// function afterConnect(status)
JObject jcallback = req_wrap->jcallback();
IOTJS_ASSERT(jcallback.IsFunction());
// Only parameter is status code.
JArgList args(1);
args.Add(JVal::Number(status));
// Make callback.
MakeCallback(jcallback, JObject::Null(), args);
// Release request wrapper.
delete req_wrap;
}