コード例 #1
0
static int stringdb_index(lua_State *L)
{
TRY_START
        check_args(L,2);
        GET_UD_MACRO(StringDB,self,1,STRINGDB_TAG);
        if (lua_type(L,2)==LUA_TNUMBER) {
                if (self.size()==0) {
                        my_lua_error(L,"Empty stringdb");
                }
                unsigned short index=check_t<unsigned short>(L,2,1,self.size());
                lua_pushstring(L,self[index-1].c_str());
        } else {
                std::string key  = luaL_checkstring(L,2);
                if (key=="add") {
                        push_cfunction(L,stringdb_add);
                } else if (key=="clear") {
                        push_cfunction(L,stringdb_clear);
                } else if (key=="table") {
                        lua_createtable(L, self.size(), 0);
                        for (unsigned int i=0 ; i<self.size() ; i++) {
                                lua_pushnumber(L,i+1);
                                lua_pushstring(L,self[i].c_str());
                                lua_settable(L,-3);
                        }
                } else {
                        my_lua_error(L,"Not a readable StringDB member: "+key);
                }
        }
        return 1;
TRY_END
}
コード例 #2
0
static int global_physics_test (lua_State *L)
{
TRY_START
        LuaTestCallback lcb;
        push_cfunction(L, my_lua_error_handler);
        int error_handler = lua_gettop(L);
        if (lua_gettop(L)==5) {
                float radius = lua_tonumber(L, 1);
                Vector3 pos = check_v3(L, 2);
                bool only_dyn = check_bool(L, 3);
                if (lua_type(L, 4) != LUA_TFUNCTION)
                        my_lua_error(L, "Parameter 4 should be a function.");

                physics_test_sphere(radius, pos, only_dyn, lcb);
                lcb.pushResults(L, 4, error_handler);
        } else {
                check_args(L, 6);
                std::string col_mesh_name = check_path(L, 1);
                DiskResource *col_mesh_ = disk_resource_get_or_make(col_mesh_name);
                CollisionMesh *col_mesh = dynamic_cast<CollisionMesh*>(col_mesh_);
                if (col_mesh==NULL) my_lua_error(L, "Not a collision mesh: \""+col_mesh_name+"\"");
                if (!col_mesh->isLoaded()) my_lua_error(L, "Not loaded: \""+col_mesh_name+"\"");
                Vector3 pos = check_v3(L, 2);
                Quaternion quat = check_quat(L, 3);
                bool only_dyn = check_bool(L, 4);
                if (lua_type(L, 5) != LUA_TFUNCTION)
                        my_lua_error(L, "Parameter 5 should be a function.");

                physics_test(col_mesh, pos, quat, only_dyn, lcb);
                lcb.pushResults(L, 5, error_handler);
        }
        lua_pop(L, 1); // error handler
        return 0;
TRY_END
}
コード例 #3
0
static int global_class_add (lua_State *L)
{
TRY_START
        check_args(L,3);
        std::string name = check_path(L,1);
        if (!lua_istable(L,2))
                my_lua_error(L,"Second parameter should be a table");
        if (!lua_istable(L,3))
                my_lua_error(L,"Third parameter should be a table");
        class_add(L, name);
        return 1;
TRY_END
}
コード例 #4
0
static int global_physics_sweep_col_mesh (lua_State *L)
{
TRY_START
        int base_line = 7;
        check_args_min(L, base_line);

        std::string col_mesh_name = check_path(L, 1);
        DiskResource *col_mesh_ = disk_resource_get_or_make(col_mesh_name);
        CollisionMesh *col_mesh = dynamic_cast<CollisionMesh*>(col_mesh_);
        Quaternion q = check_quat(L, 2);
        Vector3 start = check_v3(L, 3);
        Vector3 ray = check_v3(L, 4);
        bool nearest_only = check_bool(L, 5);
        unsigned long flags = check_t<unsigned long>(L, 6);
        if (lua_type(L, 7) != LUA_TFUNCTION)
                my_lua_error(L, "Parameter 5 should be a function.");

        LuaSweepCallback lcb(nearest_only, flags);
        init_cast_blacklist(L, base_line, lcb);

        physics_sweep_col_mesh(start, q, start + ray, q, lcb, col_mesh);

        push_cfunction(L, my_lua_error_handler);
        int error_handler = lua_gettop(L);

        lcb.pushResults(L, 7, error_handler);
        return 0;
TRY_END
}
コード例 #5
0
void GritObject::getField (lua_State *L, const std::string &f) const
{
    if (gritClass==NULL) GRIT_EXCEPT("Object destroyed");

    const char *err = userValues.luaGet(L, f);
    if (err) my_lua_error(L, err);
    if (!lua_isnil(L, -1)) return;
    lua_pop(L, 1);
    // try class instead
    gritClass->get(L, f);
}
コード例 #6
0
static int plot_newindex(lua_State *L)
{
TRY_START
        check_args(L,3);
        GET_UD_MACRO(Plot,self,1,PLOT_TAG);
        (void) self;
        std::string key  = luaL_checkstring(L,2);
        if (false) {
        } else {
                my_lua_error(L,"Not a writeable Plot member: "+key);
        }
        return 0;
TRY_END
}
コード例 #7
0
static int stringdb_newindex(lua_State *L)
{
TRY_START
        check_args(L,3);
        GET_UD_MACRO(StringDB,self,1,STRINGDB_TAG);
        std::string key  = luaL_checkstring(L,2);
        if (lua_type(L,2)==LUA_TNUMBER) {
                if (self.size()==0) {
                        my_lua_error(L,"Empty stringdb");
                }
                unsigned short index=check_t<unsigned short>(L,2,1,self.size());
                std::string v = luaL_checkstring(L,3);
                self[index-1] = v;
        } else {
                if (key=="value") {
                        GET_UD_MACRO(StringDB,v,3,STRINGDB_TAG);
                        self = v;
                } else {
                        my_lua_error(L,"Not a writeable StringDB member: "+key);
                }
        }
        return 0;
TRY_END
}
コード例 #8
0
static int gritcls_newindex (lua_State *L)
{
TRY_START
        check_args(L,3);
        GET_UD_MACRO(GritClass,self,1,GRITCLS_TAG);
        std::string key = check_string(L,2);

        if (key=="name") {
                my_lua_error(L,"Not a writeable GritClass member: "+key);
        } else if (key=="parent") {
                self.setParent(L);
        } else {
                self.set(L,key);
        }

        return 0;
TRY_END
}
コード例 #9
0
int plot_make (lua_State *L)
{
TRY_START
        Plot *self = new Plot();
        check_args(L,1);
        int table = lua_gettop(L);
        if (!lua_istable(L,table))
                my_lua_error(L,"Parameter should be a table");
        for (lua_pushnil(L) ; lua_next(L,table)!=0 ; lua_pop(L,1)) {
                // the name is held in the object anyway
                float k = check_float(L,-2);
                float v = check_float(L,-1);
                self->addPoint(k,v);
        }
        self->commit();
        push(L,self,PLOT_TAG);
        return 1;
TRY_END
}
コード例 #10
0
int stringdb_make (lua_State *L)
{
TRY_START
        StringDB self;
        if (lua_gettop(L)==1) {
                int table = lua_gettop(L);
                if (!lua_istable(L,table))
                        my_lua_error(L,"Parameter should be a table");
                for (lua_pushnil(L) ; lua_next(L,table)!=0 ; lua_pop(L,1)) {
                        // the name is held in the object anyway
                        std::string str = luaL_checkstring(L,-1);
                        self.push_back(str);
                }
        } else {
                check_args(L,0);
        }
        push(L,new StringDB(self),STRINGDB_TAG);
        return 1;
TRY_END
}
コード例 #11
0
static int plot_index(lua_State *L)
{
TRY_START
        typedef Plot::Map Map;
        typedef Plot::MI MI;
        check_args(L,2);
        GET_UD_MACRO(Plot,self,1,PLOT_TAG);
        if (lua_type(L,2)==LUA_TNUMBER) {
                float k = check_float(L,2);
                lua_pushnumber(L,self[k]);
        } else {
                std::string key  = luaL_checkstring(L,2);
                if (key=="minX") {
                        lua_pushnumber(L,self.minX());
                } else if (key=="maxX") {
                        lua_pushnumber(L,self.maxX());
                } else if (key=="points") {
                        Map data = self.getPoints();
                        lua_createtable(L, data.size(), 0);
                        for (MI i=data.begin(), i_=data.end() ; i!=i_ ; ++i) {
                                lua_pushnumber(L,i->first);
                                lua_pushnumber(L,i->second);
                                lua_settable(L,-3);
                        }
                } else if (key=="tangents") {
                        Map data = self.getTangents();
                        lua_createtable(L, data.size(), 0);
                        for (MI i=data.begin(), i_=data.end() ; i!=i_ ; ++i) {
                                lua_pushnumber(L,i->first);
                                lua_pushnumber(L,i->second);
                                lua_settable(L,-3);
                        }
                } else {
                        my_lua_error(L,"Not a readable Plot member: "+key);
                }
        }
        return 1;
TRY_END
}
コード例 #12
0
ファイル: interpreter.cpp プロジェクト: grit-engine/luaimg
static int global_include (lua_State *L)
{
    check_args(L,1);
    std::string filename = luaL_checkstring(L,1);

    lua_pushcfunction(L, my_lua_error_handler_cerr);
    int error_handler = lua_gettop(L);

    int status = luaL_loadfile(L, filename.c_str());
    if (status) {
        const char *str = lua_tostring(L,-1);
        // call error function manually, lua will not do this for us in lua_load
        my_lua_error(L, str);
    } else {
        status = lua_pcall(L, 0, 0, error_handler);
        if (status) {
            lua_pop(L,1); //message
        }
    }

    lua_pop(L,1); // error handler
    return 0;
}
コード例 #13
0
static int rbody_newindex (lua_State *L)
{
TRY_START
        check_args(L, 3);
        GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG);
        const char *key = luaL_checkstring(L, 2);
        if (!::strcmp(key, "linearVelocity")) {
                Vector3 v = check_v3(L, 3);
                self.setLinearVelocity(v);
        } else if (!::strcmp(key, "angularVelocity")) {
                Vector3 v = check_v3(L, 3);
                self.setAngularVelocity(v);
        } else if (!::strcmp(key, "worldPosition")) {
                Vector3 v = check_v3(L, 3);
                self.setPosition(v);
        } else if (!::strcmp(key, "worldOrientation")) {
                Quaternion v = check_quat(L, 3);
                self.setOrientation(v);
        } else if (!::strcmp(key, "contactProcessingThreshold")) {
                float v = check_float(L, 3);
                self.setContactProcessingThreshold(v);
        } else if (!::strcmp(key, "linearDamping")) {
                float v = check_float(L, 3);
                self.setLinearDamping(v);
        } else if (!::strcmp(key, "angularDamping")) {
                float v = check_float(L, 3);
                self.setAngularDamping(v);
        } else if (!::strcmp(key, "linearSleepThreshold")) {
                float v = check_float(L, 3);
                self.setLinearSleepThreshold(v);
        } else if (!::strcmp(key, "angularSleepThreshold")) {
                float v = check_float(L, 3);
                self.setAngularSleepThreshold(v);
        } else if (!::strcmp(key, "mass")) {
                float v = check_float(L, 3);
                self.setMass(v);
        } else if (!::strcmp(key, "ghost")) {
                bool v = check_bool(L, 3);
                self.setGhost(v);
        } else if (!::strcmp(key, "updateCallback")) {
                self.updateCallbackPtr.set(L);
        } else if (!::strcmp(key, "stepCallback")) {
                self.stepCallbackPtr.set(L);
        } else if (!::strcmp(key, "collisionCallback")) {
                self.collisionCallbackPtr.set(L);
        } else if (!::strcmp(key, "stabiliseCallback")) {
                self.stabiliseCallbackPtr.set(L);
        } else if (!::strcmp(key, "inertia")) {
                Vector3 v = check_v3(L, 3);
                self.setInertia(v);
        } else if (!::strcmp(key, "owner")) {
                if (lua_isnil(L, 3)) {
                        self.owner.setNull();
                } else {
                        GET_UD_MACRO(GritObjectPtr, v, 3, GRITOBJ_TAG);
                        self.owner = v;
                }

        } else {
               my_lua_error(L, "Not a writeable RigidBody member: "+std::string(key));
        }
        return 0;
TRY_END
}
コード例 #14
0
static int rbody_index (lua_State *L)
{
TRY_START
        check_args(L, 2);
        GET_UD_MACRO(RigidBody, self, 1, RBODY_TAG);
        const char *key = luaL_checkstring(L, 2);
        if (!::strcmp(key, "force")) {
                push_cfunction(L, rbody_force);
        } else if (!::strcmp(key, "impulse")) {
                push_cfunction(L, rbody_impulse);
        } else if (!::strcmp(key, "torque")) {
                push_cfunction(L, rbody_torque);
        } else if (!::strcmp(key, "torqueImpulse")) {
                push_cfunction(L, rbody_torque_impulse);

        } else if (!::strcmp(key, "procObjMaterials")) {
                std::vector<int> mats;
                self.colMesh->getProcObjMaterials(mats);
                lua_createtable(L, mats.size(), 0);
                for (size_t j=0 ; j<mats.size(); ++j) {
                        lua_pushstring(L, phys_mats.getMaterial(mats[j])->name.c_str());
                        lua_rawseti(L, -2, j+1);
                }
        } else if (!::strcmp(key, "scatter")) {
                push_cfunction(L, rbody_scatter);
        } else if (!::strcmp(key, "rangedScatter")) {
                push_cfunction(L, rbody_ranged_scatter);

        } else if (!::strcmp(key, "activate")) {
                push_cfunction(L, rbody_activate);
        } else if (!::strcmp(key, "deactivate")) {
                push_cfunction(L, rbody_deactivate);
        } else if (!::strcmp(key, "destroy")) {
                push_cfunction(L, rbody_destroy);

        } else if (!::strcmp(key, "linearSleepThreshold")) {
                lua_pushnumber(L, self.getLinearSleepThreshold());
        } else if (!::strcmp(key, "angularSleepThreshold")) {
                lua_pushnumber(L, self.getAngularSleepThreshold());

        } else if (!::strcmp(key, "worldPosition")) {
                push_v3(L, self.getPosition());
        } else if (!::strcmp(key, "worldOrientation")) {
                push_quat(L, self.getOrientation());

        } else if (!::strcmp(key, "localToWorld")) {
                push_cfunction(L, rbody_local_to_world);
        } else if (!::strcmp(key, "worldToLocal")) {
                push_cfunction(L, rbody_world_to_local);

        } else if (!::strcmp(key, "linearVelocity")) {
                push_v3(L, self.getLinearVelocity());
        } else if (!::strcmp(key, "angularVelocity")) {
                push_v3(L, self.getAngularVelocity());
        } else if (!::strcmp(key, "getLocalVelocity")) {
                push_cfunction(L, rbody_local_vel);

        } else if (!::strcmp(key, "contactProcessingThreshold")) {
                lua_pushnumber(L, self.getContactProcessingThreshold());

        } else if (!::strcmp(key, "linearDamping")) {
                lua_pushnumber(L, self.getLinearDamping());
        } else if (!::strcmp(key, "angularDamping")) {
                lua_pushnumber(L, self.getAngularDamping());

        } else if (!::strcmp(key, "mass")) {
                lua_pushnumber(L, self.getMass());
        } else if (!::strcmp(key, "inertia")) {
                push_v3(L, self.getInertia());
        } else if (!::strcmp(key, "ghost")) {
                lua_pushboolean(L, self.getGhost());

        } else if (!::strcmp(key, "numParts")) {
                lua_pushnumber(L, self.getNumElements());
        } else if (!::strcmp(key, "getPartEnabled")) {
                push_cfunction(L, rbody_get_part_enabled);
        } else if (!::strcmp(key, "setPartEnabled")) {
                push_cfunction(L, rbody_set_part_enabled);
        } else if (!::strcmp(key, "getPartPositionInitial")) {
                push_cfunction(L, rbody_get_part_position_initial);
        } else if (!::strcmp(key, "getPartPositionOffset")) {
                push_cfunction(L, rbody_get_part_position_offset);
        } else if (!::strcmp(key, "setPartPositionOffset")) {
                push_cfunction(L, rbody_set_part_position_offset);
        } else if (!::strcmp(key, "getPartOrientationInitial")) {
                push_cfunction(L, rbody_get_part_orientation_initial);
        } else if (!::strcmp(key, "getPartOrientationOffset")) {
                push_cfunction(L, rbody_get_part_orientation_offset);
        } else if (!::strcmp(key, "setPartOrientationOffset")) {
                push_cfunction(L, rbody_set_part_orientation_offset);

        } else if (!::strcmp(key, "meshName")) {
                push_string(L, self.colMesh->getName());

        } else if (!::strcmp(key, "owner")) {
                if (self.owner.isNull()) {
                        lua_pushnil(L);
                } else {
                        push_gritobj(L, self.owner);
                }

        } else if (!::strcmp(key, "updateCallback")) {
                self.updateCallbackPtr.push(L);
        } else if (!::strcmp(key, "stepCallback")) {
                self.stepCallbackPtr.push(L);
        } else if (!::strcmp(key, "collisionCallback")) {
                self.collisionCallbackPtr.push(L);
        } else if (!::strcmp(key, "stabiliseCallback")) {
                self.stabiliseCallbackPtr.push(L);
        } else {
                my_lua_error(L, "Not a readable RigidBody member: "+std::string(key));
        }
        return 1;
TRY_END
}
コード例 #15
0
static int gritobj_newindex (lua_State *L)
{
TRY_START
        check_args(L,3);
        GET_UD_MACRO(GritObjectPtr,self,1,GRITOBJ_TAG);
        std::string key = check_string(L,2);

        if (key=="destroy") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="near") {
                if (lua_isnil(L,3)) {
                        self->setNearObj(self,GritObjectPtr());
                } else {
                        GET_UD_MACRO(GritObjectPtr,v,3,GRITOBJ_TAG);
                        self->setNearObj(self,v);
                }
        } else if (key=="far") {
                if (lua_isnil(L,3)) {
                        self->setNearObj(self,GritObjectPtr());
                } else {
                        GET_UD_MACRO(GritObjectPtr,v,3,GRITOBJ_TAG);
                        self->setFarObj(self,v);
                }
        } else if (key=="fade") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="updateSphere") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="pos") {
                self->updateSphere(check_v3(L,3));
        } else if (key=="renderingDistance") {
                self->updateSphere(check_float(L,3));
        } else if (key=="getSphere") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="activated") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="deactivate") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="activate") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="instance") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="hintAdvancePrepare") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="getAdvancePrepareHints") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="destroyed") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="class") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="className") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="name") {
                my_lua_error(L,"Not a writeable GritObject member: "+key);
        } else if (key=="needsFrameCallbacks") {
                self->setNeedsFrameCallbacks(self, check_bool(L,3));
        } else if (key=="needsStepCallbacks") {
                self->setNeedsStepCallbacks(self, check_bool(L,3));
        } else {
                GritClass *c = self->getClass();
                if (c==NULL) my_lua_error(L,"GritObject destroyed");
                const char *err = self->userValues.luaSet(L);
                if (err) my_lua_error(L, err);
        }

        return 0;
TRY_END
}
コード例 #16
0
static int gritobj_index (lua_State *L)
{
TRY_START
        check_args(L,2);
        GET_UD_MACRO(GritObjectPtr,self,1,GRITOBJ_TAG);
        std::string key = check_string(L,2);
        if (key=="destroy") {
                push_cfunction(L,gritobj_destroy);
        } else if (key=="activated") {
                lua_pushboolean(L,self->isActivated());
        } else if (key=="near") {
                push_gritobj(L,self->getNearObj());
        } else if (key=="far") {
                push_gritobj(L,self->getFarObj());
        } else if (key=="fade") {
                lua_pushnumber(L,self->getFade());
        } else if (key=="updateSphere") {
                push_cfunction(L,gritobj_update_sphere);
        } else if (key=="pos") {
                push_v3(L, self->getPos());
        } else if (key=="renderingDistance") {
                lua_pushnumber(L, self->getR());
        } else if (key=="deactivate") {
                push_cfunction(L,gritobj_deactivate);
        } else if (key=="activate") {
                push_cfunction(L,gritobj_activate);
        } else if (key=="instance") {
                self->pushLuaTable(L);
        } else if (key=="addDiskResource") {
                push_cfunction(L,gritobj_add_disk_resource);
        } else if (key=="reloadDiskResources") {
                push_cfunction(L,gritobj_reload_disk_resource);
/*
        } else if (key=="getAdvancePrepareHints") {
                push_cfunction(L,gritobj_get_advance_prepare_hints);
*/
        } else if (key=="destroyed") {
                lua_pushboolean(L,self->getClass()==NULL);
        } else if (key=="class") {
                GritClass *c = self->getClass();
                if (c==NULL) my_lua_error(L,"GritObject destroyed");
                push_gritcls(L,c);
        } else if (key=="className") {
                GritClass *c = self->getClass();
                if (c==NULL) my_lua_error(L,"GritObject destroyed");
                lua_pushstring(L,c->name.c_str());
        } else if (key=="name") {
                lua_pushstring(L,self->name.c_str());
        } else if (key=="needsFrameCallbacks") {
                lua_pushboolean(L,self->getNeedsFrameCallbacks());
        } else if (key=="needsStepCallbacks") {
                lua_pushboolean(L,self->getNeedsStepCallbacks());
        } else if (key=="dump") {
                self->userValues.dump(L);
        } else {
                GritClass *c = self->getClass();
                if (c==NULL) my_lua_error(L,"GritObject destroyed");
                const char *err = self->userValues.luaGet(L);
                if (err) my_lua_error(L, err);
                if (!lua_isnil(L,-1)) return 1;
                lua_pop(L,1);
                // try class instead
                c->get(L,key);
        }
        return 1;
TRY_END
}