本文整理汇总了C++中luaplus::LuaObject::IsTable方法的典型用法代码示例。如果您正苦于以下问题:C++ LuaObject::IsTable方法的具体用法?C++ LuaObject::IsTable怎么用?C++ LuaObject::IsTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类luaplus::LuaObject
的用法示例。
在下文中一共展示了LuaObject::IsTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createEntityWithSize
int createEntityWithSize(const char* entityResource, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaSize)
{
if(!luaPosition.IsTable())
{
CORE_LOG("LUA", "Invalid position object passed to create_entity.");
return INVALID_ENTITY_ID;
}
if(!luaSize.IsTable())
{
CORE_LOG("LUA", "Invalid size object passed to create_entity.");
return INVALID_ENTITY_ID;
}
sf::Vector2f position = tableToVec2<sf::Vector2f>(luaPosition);
sf::Vector2f size = tableToVec2<sf::Vector2f>(luaSize);
artemis::Entity& entity = WorldLocator::getObject()->createEntity();
// Create entity
if(!EntityFactory::get().loadFromFile(entityResource, entity))
{
CORE_ERROR("Failed to load entity from file: " + std::string(entityResource));
return INVALID_ENTITY_ID;
}
Transform* pTransform = safeGetComponent<Transform>(&entity);
if(!pTransform)
{
entity.addComponent(new Transform(position.x, position.y));
}
else
{
pTransform->position = position;
}
// Get physics comp
DynamicBody* pDynamicBody = safeGetComponent<DynamicBody>(&entity);
if(pDynamicBody)
{
// Set dimensions, will be initialized later
pDynamicBody->setDimensions(size.x, size.y);
}
else
{
entity.addComponent(new DynamicBody(size.x, size.y));
}
// commit entity changes
entity.refresh();
CORE_LOG("LUA", "Created entity from: " + std::string(entityResource));
return entity.getId();
}
示例2: SetColorFromLua
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
bool SetColorFromLua(const LuaPlus::LuaObject &colorData, Vector4 &color)
{
if(!colorData.IsTable()) {
return (false);
}
LuaPlus::LuaObject rData = colorData["r"];
LuaPlus::LuaObject gData = colorData["g"];
LuaPlus::LuaObject bData = colorData["b"];
LuaPlus::LuaObject aData = colorData["a"];
if(!rData.IsNumber() || !gData.IsNumber() || !bData.IsNumber() || !aData.IsNumber()) {
return (false);
}
F32 r = static_cast<F32>(rData.GetNumber());
F32 g = static_cast<F32>(gData.GetNumber());
F32 b = static_cast<F32>(bData.GetNumber());
F32 a = static_cast<F32>(aData.GetNumber());
Clamp<F32>(r, 0.0f, 1.0f);
Clamp<F32>(g, 0.0f, 1.0f);
Clamp<F32>(b, 0.0f, 1.0f);
Clamp<F32>(a, 0.0f, 1.0f);
color.Set(r, g, b, a);
return (true);
}
示例3: LoadScene
bool LoadScene(const std::string &sceneName)
{
std::string fullPath;
fullPath = "Scenes/";
fullPath += sceneName;
fullPath += ".lua";
LuaPlus::LuaStateAuto state;
state = LuaPlus::LuaState::Create();
int retVal = state->DoFile(fullPath.c_str());
_ASSERT(retVal==0);
LuaPlus::LuaObject meshList = state->GetGlobals()["MeshList"];
_ASSERT(meshList.IsTable());
int numMeshes = meshList.GetCount();
for(int meshIndex=1;meshIndex <= meshList.GetCount(); meshIndex++)
{
LuaPlus::LuaObject meshObj = meshList[meshIndex];
LuaPlus::LuaObject nameObj = meshObj["Name"];
_ASSERT(nameObj.IsString());
std::string meshName = nameObj.GetString();
MeshManager::GetInstance().Load(meshName,meshObj);
Instance *inst = InstanceManager::GetInstance().CreateInstance(meshName);
inst->SetMeshName(meshName);
}
return true;
}
示例4: Get
// ****************************************************************************
// ****************************************************************************
Instance * InstanceManager::Load(const std::string &name)
{
Instance *inst = Get(name);
if(inst != NULL)
return inst;
std::string fullPath = "Meshes/";
fullPath += name;
fullPath += ".lua";
LuaPlus::LuaState *state = LuaPlus::LuaState::Create();
_ASSERT(state != NULL);
int retVal = state->DoFile(fullPath.c_str());
_ASSERT(retVal == 0);
LuaPlus::LuaObject shaderObj = state->GetGlobals()["MeshList"];
_ASSERT(shaderObj.IsTable());
inst = new Instance;
_ASSERT(inst != NULL);
m_database[name] = inst;
return inst;
}
示例5: createActor
int ant::InternalLuaScriptExports::createActor( const char* actorArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaRotation )
{
if (!luaPosition.IsTable())
{
GCC_ERROR("Invalid object passed to createActor(); type = " + std::string(luaPosition.TypeName()));
return INVALID_ACTOR_ID;
}
if (!luaRotation.IsNumber())
{
GCC_ERROR("Invalid object passed to createActor(); type = " + std::string(luaRotation.TypeName()));
return INVALID_ACTOR_ID;
}
sf::Vector2f pos(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat());
ant::Real rot = luaRotation.GetFloat();
TiXmlElement *overloads = NULL;
ActorStrongPtr actor = ant::ISFMLApp::getApp()->getGameLogic()->createActor(actorArchetype, overloads, &pos, &rot);
if (actor)
{
shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(actor->getId()));
IEventManager::instance()->queueEvent(pNewActorEvent);
return actor->getId();
}
return INVALID_ACTOR_ID;
}
示例6: ApplyTorque
void InternalScriptExports::ApplyTorque(LuaPlus::LuaObject axisLua, float force, int actorId)
{
if (axisLua.IsTable())
{
Vec3 axis(axisLua["x"].GetFloat(), axisLua["y"].GetFloat(), axisLua["z"].GetFloat());
g_pApp->m_pGame->VGetGamePhysics()->VApplyTorque(axis, force, actorId);
return;
}
GCC_ERROR("Invalid object passed to ApplyTorque(); type = " + std::string(axisLua.TypeName()));
}
示例7: ApplyForce
// apply force to an object from lua
void LuaInternalScriptExports::ApplyForce(LuaPlus::LuaObject normalDirectionLua, float force, int gameObjectId)
{
if (normalDirectionLua.IsTable())
{
Vec3 normalDir(normalDirectionLua["x"].GetFloat(), normalDirectionLua["y"].GetFloat(), normalDirectionLua["z"].GetFloat());
g_pApp->m_pGame->GetGamePhysics()->ApplyForce(normalDir, force, gameObjectId);
return;
}
CB_ERROR("Invalid object passed to ApplyForce(). Type = " + std::string(normalDirectionLua.TypeName()));
}
示例8: GetYRotationFromVector
float InternalScriptExports::GetYRotationFromVector(LuaPlus::LuaObject vec3)
{
if (vec3.IsTable())
{
Vec3 lookAt(vec3["x"].GetFloat(), vec3["y"].GetFloat(), vec3["z"].GetFloat());
return ::GetYRotationFromVector(lookAt);
}
GCC_ERROR("Invalid object passed to GetYRotationFromVector(); type = " + std::string(vec3.TypeName()));
return 0;
}
示例9: GetYRotationFromVector
// get the y rotation in radians from a lua vec3
float LuaInternalScriptExports::GetYRotationFromVector(LuaPlus::LuaObject vec3)
{
// make sure vec3 is a table
if (vec3.IsTable())
{
Vec3 lookAt(vec3["x"].GetFloat(), vec3["y"].GetFloat(), vec3["z"].GetFloat());
// use the GetYRotationFromVector from math.h
return ::GetYRotationFromVector(lookAt);
}
CB_ERROR("Invalid object passed to GetYRotationFromVector(); type = " + std::string(vec3.TypeName()));
return 0;
}
示例10: RegisterEventTypeWithScript
//---------------------------------------------------------------------------------------------------------------------
// This function is called to register an event type with the script to link them. The simplest way to do this is
// with the REGISTER_SCRIPT_EVENT() macro, which calls this function.
//---------------------------------------------------------------------------------------------------------------------
void ScriptEvent::RegisterEventTypeWithScript(const char* key, EventType type)
{
// get or create the EventType table
LuaPlus::LuaObject eventTypeTable = LuaStateManager::Get()->GetGlobalVars().GetByName("EventType");
if (eventTypeTable.IsNil())
eventTypeTable = LuaStateManager::Get()->GetGlobalVars().CreateTable("EventType");
// error checking
GCC_ASSERT(eventTypeTable.IsTable());
GCC_ASSERT(eventTypeTable[key].IsNil());
// add the entry
eventTypeTable.SetNumber(key, (double)type);
}
示例11: CreateGameObject
// create a game object from lua
int LuaInternalScriptExports::CreateGameObject(const char* objectArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaYawPitchRoll)
{
// lua position must be a table
if (!luaPosition.IsTable())
{
CB_ERROR("Invalid object passed to CreateGameObject(). Type = " + std::string(luaPosition.TypeName()));
return INVALID_GAMEOBJECT_ID;
}
// lua yawPitchRoll must be a table
if (!luaYawPitchRoll.IsTable())
{
CB_ERROR("Invalid object passed to CreateGameObject(). Type = " + std::string(luaYawPitchRoll.TypeName()));
return INVALID_GAMEOBJECT_ID;
}
Vec3 position(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat(), luaPosition["z"].GetFloat());
Vec3 yawPitchRoll(luaYawPitchRoll["x"].GetFloat(), luaYawPitchRoll["y"].GetFloat(), luaYawPitchRoll["z"].GetFloat());
// build the transform for the object
Mat4x4 transform;
transform.BuildYawPitchRoll(yawPitchRoll.x, yawPitchRoll.y, yawPitchRoll.z);
transform.SetPosition(position);
// create the object
TiXmlElement* overloads = nullptr;
StrongGameObjectPtr pObject = g_pApp->m_pGame->CreateGameObject(objectArchetype, overloads, &transform);
// fire the new object created event
if (pObject)
{
shared_ptr<Event_NewGameObject> pNewObjectEvent(CB_NEW Event_NewGameObject(pObject->GetId()));
IEventManager::Get()->QueueEvent(pNewObjectEvent);
return pObject->GetId();
}
return INVALID_GAMEOBJECT_ID;
}
示例12: IdentifyLuaObjectType
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
void LuaStateManager::IdentifyLuaObjectType(LuaPlus::LuaObject &objToTest)
{
assert(!objToTest.IsNil() && "Nil!");
assert(!objToTest.IsBoolean() && "Boolean!");
assert(!objToTest.IsCFunction() && "C-Function!");
assert(!objToTest.IsFunction() && "Function!");
assert(!objToTest.IsInteger() && "Integer!");
assert(!objToTest.IsLightUserData() && "Light User Data!");
assert(!objToTest.IsNone() && "None!");
assert(!objToTest.IsNumber() && "Number!");
assert(!objToTest.IsString() && "String!");
assert(!objToTest.IsTable() && "Table!");
assert(!objToTest.IsUserData() && "User Data!");
assert(!objToTest.IsWString() && "Wide String!");
assert(0 && "UNKNOWN!");
}
示例13: getGlobalVars
LuaPlus::LuaObject ant::LuaStateManager::createPath( const std::string& path, bool ignoreLastElement /*= false*/ )
{
StringVec splitPath;
Split(path,splitPath, '.');
if (ignoreLastElement)
{
splitPath.pop_back();
}
LuaPlus::LuaObject context = getGlobalVars();
for (auto it = splitPath.begin() ; it != splitPath.end() ; it++)
{
// Is the context valid?
if (context.IsNil())
{
GCC_ERROR("Something broke in CreatePath(); bailing out (element == " + (*it) + ")");
return context; // this will be nil
}
// grab whatever exists for this element
const std::string& element = (*it);
LuaPlus::LuaObject curr = context.GetByName(element.c_str());
if (!curr.IsTable())
{
// if the element is not a table and not nil, we clobber it
if (!curr.IsNil())
{
GCC_WARNING("Overwriting element '" + element + "' in table");
context.SetNil(element.c_str());
}
// element is either nil or was clobbered so add the new table
context.CreateTable(element.c_str());
}
context = context.GetByName(element.c_str());
}
// We have created a complete path here
return context;
}
示例14: throw
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
SliderControl::SliderControl(const LuaPlus::LuaObject &widgetScriptData, \
boost::shared_ptr<ModelViewProjStackManager> mvpStackManPtr, \
const boost::shared_ptr<GLSLShader> shaderFlatObj, \
const boost::shared_ptr<GLSLShader> shaderTexObj, \
boost::shared_ptr<FTFont> fontPtr, \
const ScreenElementId id) throw(GameException &)\
:
ControlWidget(widgetScriptData, mvpStackManPtr, shaderFlatObj, shaderTexObj, fontPtr, id)
, m_sliderPos(0.5f)
, m_sliderButPtr()
, m_sliderLineBatch()
, m_sliding(false)
, m_eventTypeId(0)
, m_lineColor(0.0f, 0.0f, 0.0f, 1.0f)
{
SetLuaSliderPosition(widgetScriptData.GetByName("SliderPosition"));
SetLuaEventId(widgetScriptData.GetByName("EventTypeId"));
std::string buttonTableName;
LuaPlus::LuaObject tableName = widgetScriptData.GetByName("ButtonTableId");
if(tableName.IsString()) {
LuaPlus::LuaObject buttonData = widgetScriptData.GetByName(tableName.GetString());
if(buttonData.IsTable()) {
m_sliderButPtr.reset(GCC_NEW ButtonControl(buttonData, mvpStackManPtr, shaderFlatObj, shaderTexObj, fontPtr, 0));
m_sliderButPtr->VSetPosition(CalculateButtonPositionFromSlider());
m_sliderButPtr->VSetText("");
m_sliderButPtr->VSetWidth(GetProjectedButtonWidth());
m_sliderButPtr->VSetHeight(GetProjectedButtonHeight());
m_sliderButPtr->VSetVisible(VIsVisible());
m_sliderButPtr->VSetEnabled(VIsEnabled());
m_sliderButPtr->SetSendEvent(false);
} else {
GF_LOG_TRACE_ERR("SliderControl::SliderControl()", "Creation of scripted slider button failed. Creating default button");
CreateDefaultButton(VGetColor(), mvpStackManPtr, fontPtr, shaderFlatObj, shaderTexObj, VIsVisible(), VIsEnabled());
}
} else {
GF_LOG_TRACE_ERR("SliderControl::SliderControl()", "Missing slider button information from script so creating default button");
CreateDefaultButton(VGetColor(), mvpStackManPtr, fontPtr, shaderFlatObj, shaderTexObj, VIsVisible(), VIsEnabled());
}
RebuildSliderLine();
}
示例15: return
// /////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////
bool SetVector3FromLua(const LuaPlus::LuaObject &dirData, Vector3 &direction)
{
if(!dirData.IsTable()) {
return (false);
}
LuaPlus::LuaObject xData = dirData["x"];
LuaPlus::LuaObject yData = dirData["y"];
LuaPlus::LuaObject zData = dirData["z"];
if(!xData.IsNumber() || !yData.IsNumber() || !zData.IsNumber()) {
return (false);
}
F32 x = static_cast<F32>(xData.GetNumber());
F32 y = static_cast<F32>(yData.GetNumber());
F32 z = static_cast<F32>(zData.GetNumber());
direction.Set(x, y, z);
return (true);
}