示例#1
0
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;
}
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    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();
    }
    // /////////////////////////////////////////////////////////////////
    //
    // /////////////////////////////////////////////////////////////////
    ListButtonControl::ListButtonControl(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 &)\
:
    ButtonControl(widgetScriptData, mvpStackManPtr, shaderFlatObj, shaderTexObj, fontPtr, id)
    , m_list()
    , m_curr()
    {
        SetLuaTextList(widgetScriptData.GetByName("TextTable"));
        if(!m_list.empty()) {
            m_curr = m_list.begin();
        }
        Init();
    }
示例#4
0
//---------------------------------------------------------------------------------------------------------------------
// This function registers all the ScriptExports functions with the scripting system.  It is called in 
// Application::Init().
//---------------------------------------------------------------------------------------------------------------------
void ScriptExports::Register(void)
{
	LuaPlus::LuaObject globals = LuaStateManager::Get()->GetGlobalVars();

	// init	
	InternalScriptExports::Init();

	// resource loading
	globals.RegisterDirect("LoadAndExecuteScriptResource", &InternalScriptExports::LoadAndExecuteScriptResource);

	// actors
	globals.RegisterDirect("CreateActor", &InternalScriptExports::CreateActor);

	// event system
	globals.RegisterDirect("RegisterEventListener", &InternalScriptExports::RegisterEventListener);
	globals.RegisterDirect("RemoveEventListener", &InternalScriptExports::RemoveEventListener);
	globals.RegisterDirect("QueueEvent", &InternalScriptExports::QueueEvent);
	globals.RegisterDirect("TriggerEvent", &InternalScriptExports::TriggerEvent);
	
	// process system
	globals.RegisterDirect("AttachProcess", &InternalScriptExports::AttachScriptProcess);

    // math
    LuaPlus::LuaObject mathTable = globals.GetByName("GccMath");
    GCC_ASSERT(mathTable.IsTable());
    mathTable.RegisterDirect("GetYRotationFromVector", &InternalScriptExports::GetYRotationFromVector);
    mathTable.RegisterDirect("WrapPi", &InternalScriptExports::WrapPi);
    mathTable.RegisterDirect("GetVectorFromRotation", &InternalScriptExports::GetVectorFromRotation);
	
	// misc
	globals.RegisterDirect("Log", &InternalScriptExports::LuaLog);
    globals.RegisterDirect("GetTickCount", &InternalScriptExports::GetTickCount);

	// Physics
	globals.RegisterDirect("ApplyForce", &InternalScriptExports::ApplyForce);
	globals.RegisterDirect("ApplyTorque", &InternalScriptExports::ApplyTorque);
}
//=============================================================
//	C Functions for registering C++ functions to Lua script
//=============================================================
void LuaScriptExports::Register()
{
	LuaPlus::LuaObject globals = LuaStateManager::Get()->GetGlobalVars();

	// init
	LuaInternalScriptExports::Init();

	// resource loading
	globals.RegisterDirect("LoadAndExecuteScriptResource", &LuaInternalScriptExports::LoadAndExecuteScriptResource);

	// gameobjects
	globals.RegisterDirect("CreateObject", &LuaInternalScriptExports::CreateGameObject);

	// events
	globals.RegisterDirect("RegisterEventListener", &LuaInternalScriptExports::RegisterEventListener);
	globals.RegisterDirect("RemoveEventListener", &LuaInternalScriptExports::RemoveEventListener);
	globals.RegisterDirect("QueueEvent", &LuaInternalScriptExports::QueueEvent);
	globals.RegisterDirect("TriggerEvent", &LuaInternalScriptExports::TriggerEvent);

	// processes
	globals.RegisterDirect("AttachProcess", &LuaInternalScriptExports::AttachScriptProcess);

	// math (these are registered to GccMath, not global
	LuaPlus::LuaObject mathTable = globals.GetByName("GccMath");
	CB_ASSERT(mathTable.IsTable());
	mathTable.RegisterDirect("GetYRotationFromVector", &LuaInternalScriptExports::GetYRotationFromVector);
	mathTable.RegisterDirect("WrapPi", &LuaInternalScriptExports::WrapPi);
	mathTable.RegisterDirect("GetVectorFromRotation", &LuaInternalScriptExports::GetVectorFromRotation);

	// misc
	globals.RegisterDirect("Log", &LuaInternalScriptExports::LuaLog);
	globals.RegisterDirect("GetTickCount", &LuaInternalScriptExports::GetTickCount);

	// physics
	globals.RegisterDirect("ApplyForce", &LuaInternalScriptExports::ApplyForce);
	globals.RegisterDirect("ApplyTorque", &LuaInternalScriptExports::ApplyTorque);
}