void ofxLua::writeTable(const string& tableName, ofxLuaFileWriter& writer, bool recursive) { if(!pushTable(tableName)) { return; } writeTable(writer, recursive); popTable(); }
void Stack::pushVariable(const Variable &var) { switch (var.getType()) { case kTypeNil: pushNil(); break; case kTypeBoolean: pushBoolean(var.getBool()); break; case kTypeNumber: pushFloat(var.getFloat()); break; case kTypeString: pushString(var.getString()); break; case kTypeTable: pushTable(var.getTable()); break; case kTypeFunction: pushFunction(var.getFunction()); break; case kTypeUserType: pushRawUserType(var.getRawUserType(), var.getExactType()); break; default: warning("Pushing a varible of type \"%s\" not supported", var.getExactType().c_str()); break; } }
void lua::FunctionWrapper::removeReference() { utils::StackCleaner cleaner(m_L, 0); // push the table on the stack pushTable(); auto tableIndex = lua_gettop(m_L); // get the ref count field lua_pushinteger(m_L, s_refCountIndex); lua_rawget(m_L, tableIndex); // extract the ref count value and decrement the value auto refCount = lua_tointeger(m_L, -1); --refCount; // remove the ref count from the stack lua_pop(m_L, 1); if (refCount == 0) { luaL_unref(m_L, LUA_REGISTRYINDEX, m_tableReference); m_tableReference = s_invalidReference; } else { lua_pushinteger(m_L, s_refCountIndex); lua_pushinteger(m_L, refCount); lua_rawset(m_L, tableIndex); } }
unsigned int ofxLua::tableSize(const string& tableName) { unsigned int size = 0; pushTable(tableName); size = tableSize(); popTable(); return size; }
/* Constructor */ EnergyLaw44::EnergyLaw44(const Law* ace_data) : EnergyOutgoingTabular<KalbachTabular>(ace_data) { const Law44* law_data = dynamic_cast<const Law44*>(ace_data); setEnergies(law_data->ein); /* Sanity check */ assert(law_data->eout_dist.size() == law_data->ein.size()); /* Create the tables */ for(vector<Law44::EnergyData>::const_iterator it = law_data->eout_dist.begin() ; it != law_data->eout_dist.end() ; ++it) pushTable(*it); }
void RKVarEditDataFrameModel::restoreObject (RObject* object, RCommandChain* chain) { RK_TRACE (EDITOR); if (object == dataframe) { pushTable (chain); } else { RKVarEditModel::restoreObject (object, chain); } }
// mstate:position() static int position(lua_State *L) { int n = lua_gettop(L); // Number of arguments if (n != 1) return luaL_error(L, "Got %d arguments expected 1", n); MotionState* mstate = checkMotionState(L); Point2 p = mstate->position(); pushTable(L, p); return 1; }
// mstate:direction() static int direction(lua_State *L) { int n = lua_gettop(L); // Number of arguments if (n == 1) { MotionState* mstate = checkMotionState(L); assert(mstate != 0); pushTable(L, mstate->direction()); } else luaL_error(L, "Got %d arguments expected 1", n); return 1; }
// mstate:velocity() static int velocity(lua_State *L) { int n = lua_gettop(L); // Number of arguments if (n == 1) { MotionState* mstate = checkMotionState(L); assert(mstate != 0); Vector2 v = mstate->velocity(); pushTable(L,v); } else luaL_error(L, "Got %d arguments expected 1", n); return 1; }
void lua::FunctionWrapper::push() { utils::StackCleaner cleaner(m_L, 1); // Push the table on the stack pushTable(); auto tableIndex = lua_gettop(m_L); lua_pushinteger(m_L, s_functionIndex); lua_rawget(m_L, tableIndex); // Swap the table with the function so that the table is at the top of the stack. lua_insert(m_L, -2); }
void LuaCore::addFunctionToLuaAndTw(int tableTop, const std::string& namespc, QTreeWidgetItem* item, int (*f)(lua_State*), const std::string& name, const QString& hint) { QTreeWidgetItem *i = new QTreeWidgetItem(item); i->setText(0, QString::fromStdString(name)); i->setText(1, QString::fromStdString(namespc + name)); i->setToolTip(0, hint); // name can be like foo(bar) but function name is just foo std::string luaFuncName; size_t pos; if((pos = name.find_first_of('(')) != std::string::npos) luaFuncName = name.substr(0, pos); else luaFuncName = name; pushTable(L, tableTop, luaFuncName, f); }
void lua::FunctionWrapper::addReference() { utils::StackCleaner cleaner(m_L, 0); // push the table on the stack pushTable(); auto tableIndex = lua_gettop(m_L); lua_pushinteger(m_L, s_refCountIndex); lua_rawget(m_L, tableIndex); auto refCount = lua_tointeger(m_L, -1); ++refCount; lua_pop(m_L, 1); lua_pushinteger(m_L, s_refCountIndex); lua_pushinteger(m_L, refCount); lua_rawset(m_L, tableIndex); }
RKVarEditDataFrameModel::RKVarEditDataFrameModel (const QString& validized_name, RContainerObject* parent_object, RCommandChain* chain, int initial_cols, QObject* parent) : RKVarEditModel (parent) { RK_TRACE (EDITOR); RObject *object = parent_object->createPendingChild (validized_name, -1, true, true); RK_ASSERT (object->isDataFrame ()); RContainerObject* df = static_cast<RContainerObject*> (object); // initialize the new object for (int i = 0; i < initial_cols; ++i) { RObject* child = df->createPendingChild (df->validizeName (QString ()), -1, false, false); RK_ASSERT (child->isVariable ()); // let's start with one (empty) row, to avoid confusion static_cast<RKVariable*> (child)->setLength (1); } init (df); // creates the pending object in the backend pushTable (chain); }
//------------------------------------------------------------------------------ void pushValue(HSQUIRRELVM vm, const Variant & v) { switch (v.getType().id) { case SN_VT_STRING: { const std::string & s = v.getString(); sq_pushstring(vm, s.c_str(), s.size()); } break; case SN_VT_INT: sq_pushinteger(vm, v.getInt()); break; case SN_VT_FLOAT: sq_pushfloat(vm, static_cast<float>(v.getFloat())); break; case SN_VT_DICTIONARY: pushTable(vm, v.getDictionary()); break; case SN_VT_ARRAY: pushArray(vm, v.getArray()); break; case SN_VT_BOOL: sq_pushbool(vm, v.getBool()); break; case SN_VT_NIL: sq_pushnull(vm); break; default: // TODO Handle special objects (color, vectors, matrix, instances etc) // UNKNOWN break; } }
void ofxLua::clearTable(const string& tableName) { pushTable(tableName); clearTable(); popTable(); }
void ofxLua::printTable(const string& tableName) { pushTable(tableName); printTable(); popTable(); }