Exemple #1
0
static int tolua_building_get_size(lua_State * L)
{
  building *self = (building *) tolua_tousertype(L, 1, 0);
  tolua_pushnumber(L, self->size);
  return 1;
}
Exemple #2
0
static int tolua_region_get_blocked(lua_State * L)
{
    region *self = (region *)tolua_tousertype(L, 1, 0);
    lua_pushboolean(L, (self->flags&RF_BLOCKED) != 0);
    return 1;
}
Exemple #3
0
static int tolua_region_get_plane(lua_State * L)
{
    region *r = (region *)tolua_tousertype(L, 1, 0);
    tolua_pushusertype(L, rplane(r), TOLUA_CAST "plane");
    return 1;
}
Exemple #4
0
static int tolua_region_tostring(lua_State * L)
{
    region *self = (region *)tolua_tousertype(L, 1, 0);
    lua_pushstring(L, regionname(self, NULL));
    return 1;
}
Exemple #5
0
static int tolua_plane_get_id(lua_State * L)
{
    plane *self = (plane *)tolua_tousertype(L, 1, 0);
    lua_pushinteger(L, self->id);
    return 1;
}
Exemple #6
0
static int tolua_region_set_morale(lua_State * L)
{
    region *r = (region *)tolua_tousertype(L, 1, 0);
    region_set_morale(r, (int)tolua_tonumber(L, 2, 0), turn);
    return 0;
}
Exemple #7
0
static int tolua_region_get_objects(lua_State * L)
{
    region *self = (region *)tolua_tousertype(L, 1, 0);
    tolua_pushusertype(L, (void *)&self->attribs, USERTYPE_DICT);
    return 1;
}
Exemple #8
0
static int tolua_building_get_region(lua_State * L)
{
  building *self = (building *) tolua_tousertype(L, 1, 0);
  tolua_pushusertype(L, building_getregion(self), TOLUA_CAST "region");
  return 1;
}
Exemple #9
0
static int tolua_building_set_region(lua_State * L)
{
  building *self = (building *) tolua_tousertype(L, 1, 0);
  building_setregion(self, (region *) tolua_tousertype(L, 2, 0));
  return 0;
}
Exemple #10
0
static int tolua_building_destroy(lua_State * L)
{
  building *self = (building *) tolua_tousertype(L, 1, 0);
  remove_building(&self->region->buildings, self);
  return 0;
}
Exemple #11
0
static int tolua_building_get_objects(lua_State * L)
{
  building *self = (building *) tolua_tousertype(L, 1, 0);
  tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
  return 1;
}
Exemple #12
0
static int tolua_building_get_type(lua_State * L)
{
  building *self = (building *) tolua_tousertype(L, 1, 0);
  tolua_pushstring(L, self->type->_name);
  return 1;
}
Exemple #13
0
static int tolua_building_get_id(lua_State * L)
{
  building *self = (building *) tolua_tousertype(L, 1, 0);
  tolua_pushnumber(L, (lua_Number) self->no);
  return 1;
}
Exemple #14
0
static int tolua_building_set_size(lua_State * L)
{
  building *self = (building *) tolua_tousertype(L, 1, 0);
  self->size = (int)tolua_tonumber(L, 2, 0);
  return 0;
}
Exemple #15
0
static int tolua_region_set_name(lua_State * L)
{
    region *self = (region *)tolua_tousertype(L, 1, 0);
    region_setname(self, tolua_tostring(L, 2, 0));
    return 0;
}
Exemple #16
0
static int tolua_building_get_info(lua_State * L)
{
  building *self = (building *) tolua_tousertype(L, 1, 0);
  tolua_pushstring(L, self->display);
  return 1;
}
Exemple #17
0
static int tolua_region_get_morale(lua_State * L)
{
    region *r = (region *)tolua_tousertype(L, 1, 0);
    lua_pushinteger(L, region_get_morale(r));
    return 1;
}
Exemple #18
0
/* Default collect function
*/
TOLUA_API int tolua_default_collect (lua_State* tolua_S)
{
    void* self = tolua_tousertype(tolua_S,1,0);
    free(self);
    return 0;
}
Exemple #19
0
/* region mourning this turn */
static int tolua_region_get_is_mourning(lua_State * L)
{
    region *r = (region *)tolua_tousertype(L, 1, 0);
    lua_pushboolean(L, is_mourning(r, turn+1));
    return 1;
}
static int tolua_cocos2dx_EventListenerPhysicsContact_registerScriptHandler(lua_State* tolua_S)
{
    if (nullptr == tolua_S)
        return 0;
    
    int argc = 0;
    EventListenerPhysicsContact* self = nullptr;
#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
    if (!tolua_isusertype(tolua_S, 1, "cc.EventListenerPhysicsContact", 0, &tolua_err))  goto tolua_lerror;
#endif
    
    self = static_cast<EventListenerPhysicsContact*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
    if (nullptr == self) {
        tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2dx_EventListenerPhysicsContact_registerScriptHandler'\n", nullptr);
        return 0;
    }
#endif
    argc = lua_gettop(tolua_S) - 1;
    
    if (argc == 2)
    {
#if COCOS2D_DEBUG >= 1
        if (!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err) ||
            !tolua_isnumber(tolua_S, 3, 0, &tolua_err))
        {
            goto tolua_lerror;
        }
#endif
        LUA_FUNCTION handler = toluafix_ref_function(tolua_S,2,0);
        ScriptHandlerMgr::HandlerType type        = static_cast<ScriptHandlerMgr::HandlerType>((int)tolua_tonumber(tolua_S, 3, 0));
        switch (type)
        {
            case ScriptHandlerMgr::HandlerType::EVENT_PHYSICS_CONTACT_BEGIN:
            {
                ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type);
                
                self->onContactBegin = [handler](PhysicsContact& contact) -> bool{
                    LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
                    stack->pushObject(&contact, "cc.PhysicsContact");
                    bool ret = stack->executeFunctionByHandler(handler, 1);
                    stack->clean();
                    
                    return ret;
                };
            }
                break;
            case ScriptHandlerMgr::HandlerType::EVENT_PHYSICS_CONTACT_PRESOLVE:
            {
                ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type);
                
                self->onContactPreSolve = [handler](PhysicsContact& contact, PhysicsContactPreSolve& solve) -> bool{
                    LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
                    stack->pushObject(&contact, "cc.PhysicsContact");
                    tolua_pushusertype(stack->getLuaState(), &solve, "cc.PhysicsContactPreSolve");
                    bool ret = stack->executeFunctionByHandler(handler, 2);
                    stack->clean();
                    
                    return ret;
                };
            }
                break;
            case ScriptHandlerMgr::HandlerType::EVENT_PHYSICS_CONTACT_POSTSOLVE:
            {
                ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type);
                
                self->onContactPostSolve = [handler](PhysicsContact& contact, const PhysicsContactPostSolve& solve){
                    LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
                    stack->pushObject(&contact, "cc.PhysicsContact");
                    tolua_pushusertype(stack->getLuaState(), const_cast<PhysicsContactPostSolve*>(&solve), "cc.PhysicsContactPostSolve");
                    stack->executeFunctionByHandler(handler, 2);
                    stack->clean();
                };
            }
                break;
            case ScriptHandlerMgr::HandlerType::EVENT_PHYSICS_CONTACT_SEPERATE:
            {
                ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, type);
                
                self->onContactSeperate = [handler](PhysicsContact& contact){
                    LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
                    stack->pushObject(&contact, "cc.PhysicsContact");
                    stack->executeFunctionByHandler(handler, 1);
                    stack->clean();
                };
            }
                break;
            default:
                break;
        }
        return 0;
    }
    
    CCLOG("'registerScriptHandler' has wrong number of arguments: %d, was expecting %d\n", argc, 2);
    return 0;
    
#if COCOS2D_DEBUG >= 1
tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err);
    return 0;
#endif
}
Exemple #21
0
static int tolua_region_destroy(lua_State * L)
{
    region *self = (region *)tolua_tousertype(L, 1, 0);
    remove_region(&regions, self);
    return 0;
}
int lua_cocos2dx_physics_PhysicsBody_getJoints(lua_State* tolua_S)
{
    int argc = 0;
    cocos2d::PhysicsBody* cobj = nullptr;
    bool ok  = true;
    
#if COCOS2D_DEBUG >= 1
    tolua_Error tolua_err;
#endif
    
#if COCOS2D_DEBUG >= 1
    if (!tolua_isusertype(tolua_S,1,"cc.PhysicsBody",0,&tolua_err)) goto tolua_lerror;
#endif
    
    cobj = (cocos2d::PhysicsBody*)tolua_tousertype(tolua_S,1,0);
    
#if COCOS2D_DEBUG >= 1
    if (!cobj)
    {
        tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics_PhysicsBody_getJoints'", NULL);
        return 0;
    }
#endif
    
    argc = lua_gettop(tolua_S)-1;
    if (argc == 0)
    {
        do {
            
            if(!ok)
                return 0;
            auto& ret = cobj->getJoints();
            
            lua_newtable(tolua_S);
            
            if (ret.empty())
                return 1;
            
            auto iter = ret.begin();
            int  indexTable = 1;
            for (; iter != ret.end(); ++iter)
            {
                if (nullptr == *iter)
                    continue;
                
                lua_pushnumber(tolua_S, (lua_Number)indexTable);
                tolua_pushusertype(tolua_S,(void*)(*iter), getLuaTypeName(*iter, "cc.PhysicsJoint"));
                lua_rawset(tolua_S, -3);
                ++indexTable;
            }
        } while (0);
        return 1;
    }
    CCLOG("%s has wrong number of arguments: %d, was expecting %d \n", "getJoints",argc, 0);
    return 0;
    
#if COCOS2D_DEBUG >= 1
tolua_lerror:
    tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics_PhysicsBody_getJoints'.",&tolua_err);
#endif
    
    return 0;
}
Exemple #23
0
static int tolua_plane_erase(lua_State *L)
{
    plane *self = (plane *)tolua_tousertype(L, 1, 0);
    remove_plane(self);
    return 0;
}
Exemple #24
0
static int tolua_collect_Point (lua_State* tolua_S)
{
 Point* self = (Point*) tolua_tousertype(tolua_S,1,0);
 delete self;
 return 0;
}
Exemple #25
0
static int tolua_plane_tostring(lua_State * L)
{
    plane *self = (plane *)tolua_tousertype(L, 1, 0);
    lua_pushstring(L, self->name);
    return 1;
}
Exemple #26
0
static int tolua_region_get_terrain(lua_State * L)
{
    region *self = (region *)tolua_tousertype(L, 1, 0);
    tolua_pushstring(L, self->terrain->_name);
    return 1;
}
Exemple #27
0
static int tolua_region_get_y(lua_State * L)
{
    region *self = (region *)tolua_tousertype(L, 1, 0);
    lua_pushinteger(L, self->y);
    return 1;
}
Exemple #28
0
static int tolua_region_get_name(lua_State * L)
{
    region *self = (region *)tolua_tousertype(L, 1, 0);
    tolua_pushstring(L, region_getname(self));
    return 1;
}
static int tolua_building_get_name(lua_State * L)
{
    building *self = (building *)tolua_tousertype(L, 1, 0);
    tolua_pushstring(L, building_getname(self));
    return 1;
}
Exemple #30
0
static int tolua_building_set_name(lua_State * L)
{
  building *self = (building *) tolua_tousertype(L, 1, 0);
  building_setname(self, tolua_tostring(L, 2, 0));
  return 0;
}