Bladeren bron

Replace table with spaces.

Aster Jian 12 jaren geleden
bovenliggende
commit
dfc7647277

+ 30 - 30
Source/Extras/LuaScript/LuaFile.cpp

@@ -44,7 +44,7 @@ namespace Urho3D
 LuaFile::LuaFile(Context* context) :
 LuaFile::LuaFile(Context* context) :
     Resource(context),
     Resource(context),
     size_(0),
     size_(0),
-	hasLoaded_(false),
+    hasLoaded_(false),
     hasExecuted_(false)
     hasExecuted_(false)
 {
 {
 
 
@@ -90,50 +90,50 @@ bool LuaFile::Save(Serializer& dest) const
 
 
 bool LuaFile::LoadChunk(lua_State* luaState)
 bool LuaFile::LoadChunk(lua_State* luaState)
 {
 {
-	if (hasLoaded_)
-		return true;
+    if (hasLoaded_)
+        return true;
 
 
-	if (size_ == 0)
-		return false;
+    if (size_ == 0)
+        return false;
 
 
-	if (!luaState)
-		return false;
+    if (!luaState)
+        return false;
 
 
-	int top = lua_gettop(luaState);
+    int top = lua_gettop(luaState);
 
 
-	// Get file name without extension.
-	String name = GetName();
-	unsigned extPos = name.FindLast('.');
-	if (extPos != String::NPOS)
-	{
-		name = name.Substring(0, extPos);
-	}
+    // Get file name without extension.
+    String name = GetName();
+    unsigned extPos = name.FindLast('.');
+    if (extPos != String::NPOS)
+    {
+        name = name.Substring(0, extPos);
+    }
 
 
-	int error = luaL_loadbuffer(luaState, data_, size_, name.CString());
-	if (error)
-	{
-		const char* message = lua_tostring(luaState, -1);
+    int error = luaL_loadbuffer(luaState, data_, size_, name.CString());
+    if (error)
+    {
+        const char* message = lua_tostring(luaState, -1);
         LOGERROR("Load Buffer failed for " + GetName() + ": " + String(message));
         LOGERROR("Load Buffer failed for " + GetName() + ": " + String(message));
-		lua_settop(luaState, top);
-		return false;
-	}
+        lua_settop(luaState, top);
+        return false;
+    }
 
 
-	hasLoaded_ = true;
+    hasLoaded_ = true;
 
 
-	return true;
+    return true;
 }
 }
 
 
 bool LuaFile::LoadAndExecute(lua_State* luaState)
 bool LuaFile::LoadAndExecute(lua_State* luaState)
 {
 {
-	if (hasExecuted_)
-		return true;
+    if (hasExecuted_)
+        return true;
 
 
-	if (!LoadChunk(luaState))
-		return false;
+    if (!LoadChunk(luaState))
+        return false;
 
 
-	int top = lua_gettop(luaState);
+    int top = lua_gettop(luaState);
 
 
-	if (lua_pcall(luaState, 0, 0, 0))
+    if (lua_pcall(luaState, 0, 0, 0))
     {
     {
         const char* message = lua_tostring(luaState, -1);
         const char* message = lua_tostring(luaState, -1);
         LOGERROR("Lua Execute failed for " + GetName() + ": " + String(message));
         LOGERROR("Lua Execute failed for " + GetName() + ": " + String(message));

+ 10 - 10
Source/Extras/LuaScript/LuaScript.cpp

@@ -192,7 +192,7 @@ void LuaScript::ScriptSubscribeToEvent(Object* object, const String& eventName,
 
 
 void LuaScript::RegisterLoader()
 void LuaScript::RegisterLoader()
 {
 {
-	// Get package.loaders table.
+    // Get package.loaders table.
     lua_getglobal(luaState_, "package");
     lua_getglobal(luaState_, "package");
     lua_getfield(luaState_, -1, "loaders");
     lua_getfield(luaState_, -1, "loaders");
 
 
@@ -208,16 +208,16 @@ int LuaScript::Loader(lua_State* L)
     if (!cache)
     if (!cache)
         return 0;
         return 0;
 
 
-	// Get module name.
-	const char* name = luaL_checkstring(L, 1);
+    // Get module name.
+    const char* name = luaL_checkstring(L, 1);
 
 
-	// Get Lua file from module name.
-	LuaFile* luaFile = cache->GetResource<LuaFile>(String(name) + ".lua");
-	if (!luaFile)
-		return false;
+    // Get Lua file from module name.
+    LuaFile* luaFile = cache->GetResource<LuaFile>(String(name) + ".lua");
+    if (!luaFile)
+        return false;
 
 
-	// Load Lua file to Lua chunk.
-	return luaFile->LoadChunk(L) ? 1 : 0;
+    // Load Lua file to Lua chunk.
+    return luaFile->LoadChunk(L) ? 1 : 0;
 }
 }
 
 
 void LuaScript::ReplacePrint()
 void LuaScript::ReplacePrint()
@@ -344,7 +344,7 @@ void LuaScript::CallEventHandler(const String& functionName, StringHash eventTyp
 void RegisterLuaScriptLibrary(Context* context)
 void RegisterLuaScriptLibrary(Context* context)
 {
 {
     LuaFile::RegisterObject(context);
     LuaFile::RegisterObject(context);
-	LuaScriptInstance::RegisterObject(context);
+    LuaScriptInstance::RegisterObject(context);
 }
 }
 
 
 Context* GetContext()
 Context* GetContext()

+ 4 - 7
Source/Extras/LuaScript/LuaScript.h

@@ -61,11 +61,11 @@ public:
     /// Script subscribe object's event.
     /// Script subscribe object's event.
     void ScriptSubscribeToEvent(Object* object, const String& eventName, const String& functionName);
     void ScriptSubscribeToEvent(Object* object, const String& eventName, const String& functionName);
 
 
-	/// Return Lua state.
-	lua_State* GetLuaState() const { return luaState_; }
+    /// Return Lua state.
+    lua_State* GetLuaState() const { return luaState_; }
 
 
-	/// Find Lua function.
-	bool FindFunction(const String& functionName);
+    /// Find Lua function.
+    bool FindFunction(const String& functionName);
 
 
 private:
 private:
     /// Register loader.
     /// Register loader.
@@ -80,9 +80,6 @@ private:
     /// Print function.
     /// Print function.
     static int Print(lua_State* L);
     static int Print(lua_State* L);
 
 
-    /// Find Lua function.
-    // bool FindFunction(const String& functionName);
-
     /// Handle event.
     /// Handle event.
     void HandleEvent(StringHash eventType, VariantMap& eventData);
     void HandleEvent(StringHash eventType, VariantMap& eventData);
 
 

+ 113 - 113
Source/Extras/LuaScript/LuaScriptInstance.cpp

@@ -46,148 +46,148 @@ LuaScriptInstance::LuaScriptInstance(Context* context) : Component(context)
 
 
 LuaScriptInstance::~LuaScriptInstance()
 LuaScriptInstance::~LuaScriptInstance()
 {
 {
-	if (objectType_.Empty())
-		return;
-
-	LuaScript* luaScript = GetSubsystem<LuaScript>();
-	lua_State* luaState = luaScript->GetLuaState();
-
-	int top = lua_gettop(luaState);
-
-	lua_getglobal(luaState, "DestroyScriptObjectInstance");
-	if (!lua_isfunction(luaState, -1))
-	{
-		LOGERROR("Can not find lua function DestroyScriptObjectInstance.");
-		lua_settop(luaState, top);
-		return;
-	}
-
-	// Push this as second parameter.
-	tolua_pushusertype(luaState, (void*)this, "LuaScriptInstance");
-
-	// Call ObjectType:new function.
-	if (lua_pcall(luaState, 1, 0, 0) != 0)
-	{
-		const char* message = lua_tostring(luaState, -1);
-		LOGERROR("Execute Lua function failed: " + String(message));
-		lua_settop(luaState, top);
-		return;
-	}
+    if (objectType_.Empty())
+        return;
+
+    LuaScript* luaScript = GetSubsystem<LuaScript>();
+    lua_State* luaState = luaScript->GetLuaState();
+
+    int top = lua_gettop(luaState);
+
+    lua_getglobal(luaState, "DestroyScriptObjectInstance");
+    if (!lua_isfunction(luaState, -1))
+    {
+        LOGERROR("Can not find lua function DestroyScriptObjectInstance.");
+        lua_settop(luaState, top);
+        return;
+    }
+
+    // Push this as second parameter.
+    tolua_pushusertype(luaState, (void*)this, "LuaScriptInstance");
+
+    // Call ObjectType:new function.
+    if (lua_pcall(luaState, 1, 0, 0) != 0)
+    {
+        const char* message = lua_tostring(luaState, -1);
+        LOGERROR("Execute Lua function failed: " + String(message));
+        lua_settop(luaState, top);
+        return;
+    }
 }
 }
 
 
 void LuaScriptInstance::RegisterObject(Context* context)
 void LuaScriptInstance::RegisterObject(Context* context)
 {
 {
-	context->RegisterFactory<LuaScriptInstance>();
+    context->RegisterFactory<LuaScriptInstance>();
 }
 }
 
 
 bool LuaScriptInstance::CreateObject(const String& objectType)
 bool LuaScriptInstance::CreateObject(const String& objectType)
 {
 {
-	if (objectType_ == objectType)
-		return true;
-
-	LuaScript* luaScript = GetSubsystem<LuaScript>();
-	lua_State* luaState = luaScript->GetLuaState();
-
-	int top = lua_gettop(luaState);
-
-	lua_getglobal(luaState, "CreateScriptObjectInstance");
-	if (!lua_isfunction(luaState, -1))
-	{
-		LOGERROR("Can not find lua function CreateScriptObjectInstance.");
-		lua_settop(luaState, top);
-		return false;
-	}
-
-	// Get table as first paramter.
-	lua_getglobal(luaState, objectType.CString());
-	if (!lua_istable(luaState, -1))
-	{
-		LOGERROR("Can not find lua table " + objectType + ".");
-		lua_settop(luaState, top);
-		return false;
-	}
-
-	// Push this as second parameter.
-	tolua_pushusertype(luaState, (void*)this, "LuaScriptInstance");
-	
-	// Call ObjectType:new function.
-	if (lua_pcall(luaState, 2, 1, 0) != 0)
-	{
-		const char* message = lua_tostring(luaState, -1);
-		LOGERROR("Execute Lua function failed: " + String(message));
-		lua_settop(luaState, top);
-		return false;
-	}
-
-	objectType_ = objectType;
-
-	return true;
+    if (objectType_ == objectType)
+        return true;
+
+    LuaScript* luaScript = GetSubsystem<LuaScript>();
+    lua_State* luaState = luaScript->GetLuaState();
+
+    int top = lua_gettop(luaState);
+
+    lua_getglobal(luaState, "CreateScriptObjectInstance");
+    if (!lua_isfunction(luaState, -1))
+    {
+        LOGERROR("Can not find lua function CreateScriptObjectInstance.");
+        lua_settop(luaState, top);
+        return false;
+    }
+
+    // Get table as first paramter.
+    lua_getglobal(luaState, objectType.CString());
+    if (!lua_istable(luaState, -1))
+    {
+        LOGERROR("Can not find lua table " + objectType + ".");
+        lua_settop(luaState, top);
+        return false;
+    }
+
+    // Push this as second parameter.
+    tolua_pushusertype(luaState, (void*)this, "LuaScriptInstance");
+    
+    // Call ObjectType:new function.
+    if (lua_pcall(luaState, 2, 1, 0) != 0)
+    {
+        const char* message = lua_tostring(luaState, -1);
+        LOGERROR("Execute Lua function failed: " + String(message));
+        lua_settop(luaState, top);
+        return false;
+    }
+
+    objectType_ = objectType;
+
+    return true;
 }
 }
 
 
 void LuaScriptInstance::ScriptSubscribeToEvent(const String& eventName, const String& functionName)
 void LuaScriptInstance::ScriptSubscribeToEvent(const String& eventName, const String& functionName)
 {
 {
-	StringHash eventType(eventName);
-	String realFunctionName = functionName.Replaced(":", ".");
+    StringHash eventType(eventName);
+    String realFunctionName = functionName.Replaced(":", ".");
 
 
-	HashSet<Object*>* receivers = context_->GetEventReceivers(eventType);
-	if (!receivers || !receivers->Contains(this))
-		SubscribeToEvent(eventType, HANDLER(LuaScriptInstance, HandleEvent));
+    HashSet<Object*>* receivers = context_->GetEventReceivers(eventType);
+    if (!receivers || !receivers->Contains(this))
+        SubscribeToEvent(eventType, HANDLER(LuaScriptInstance, HandleEvent));
 
 
-	eventTypeToFunctionNameMap_[eventType].Insert(realFunctionName);
+    eventTypeToFunctionNameMap_[eventType].Insert(realFunctionName);
 }
 }
 
 
 bool LuaScriptInstance::PushScriptObject(lua_State* luaState)
 bool LuaScriptInstance::PushScriptObject(lua_State* luaState)
 {
 {
-	tolua_pushusertype(luaState, (void*)this, "LuaScriptInstance");
-	tolua_pushstring(luaState, "object");
+    tolua_pushusertype(luaState, (void*)this, "LuaScriptInstance");
+    tolua_pushstring(luaState, "object");
 
 
-	lua_gettable(luaState, -2);
-	if (!lua_istable(luaState, -1))
-	{
-		return false;
-	}
+    lua_gettable(luaState, -2);
+    if (!lua_istable(luaState, -1))
+    {
+        return false;
+    }
 
 
-	lua_remove(luaState, -2);
+    lua_remove(luaState, -2);
 
 
-	return true;
+    return true;
 }
 }
 
 
 void LuaScriptInstance::HandleEvent(StringHash eventType, VariantMap& eventData)
 void LuaScriptInstance::HandleEvent(StringHash eventType, VariantMap& eventData)
 {
 {
-	const HashSet<String>& functionNames = eventTypeToFunctionNameMap_[eventType];
-	for (HashSet<String>::ConstIterator i = functionNames.Begin(); i != functionNames.End(); ++i)
-		CallEventHandler(*i, eventType, eventData);
+    const HashSet<String>& functionNames = eventTypeToFunctionNameMap_[eventType];
+    for (HashSet<String>::ConstIterator i = functionNames.Begin(); i != functionNames.End(); ++i)
+        CallEventHandler(*i, eventType, eventData);
 }
 }
 
 
 void LuaScriptInstance::CallEventHandler(const String& functionName, StringHash eventType, VariantMap& eventData )
 void LuaScriptInstance::CallEventHandler(const String& functionName, StringHash eventType, VariantMap& eventData )
 {
 {
-	LuaScript* luaScript = GetSubsystem<LuaScript>();
-	lua_State* luaState = luaScript->GetLuaState();
-
-	int top = lua_gettop(luaState);
-	
-	if (!luaScript->FindFunction(functionName))
-	{
-		lua_settop(luaState, top);
-		return;
-	}
-
-	if (!PushScriptObject(luaState))
-	{
-		lua_settop(luaState, top);
-		return;
-	}
-
-	tolua_pushusertype(luaState, (void*)&eventType, "StringHash");
-	tolua_pushusertype(luaState, (void*)&eventData, "VariantMap");
-
-	if (lua_pcall(luaState, 3, 0, 0) != 0)
-	{
-		const char* message = lua_tostring(luaState, -1);
-		LOGERROR("Execute Lua function failed: " + String(message));
-		lua_settop(luaState, top);
-		return;
-	}
+    LuaScript* luaScript = GetSubsystem<LuaScript>();
+    lua_State* luaState = luaScript->GetLuaState();
+
+    int top = lua_gettop(luaState);
+    
+    if (!luaScript->FindFunction(functionName))
+    {
+        lua_settop(luaState, top);
+        return;
+    }
+
+    if (!PushScriptObject(luaState))
+    {
+        lua_settop(luaState, top);
+        return;
+    }
+
+    tolua_pushusertype(luaState, (void*)&eventType, "StringHash");
+    tolua_pushusertype(luaState, (void*)&eventData, "VariantMap");
+
+    if (lua_pcall(luaState, 3, 0, 0) != 0)
+    {
+        const char* message = lua_tostring(luaState, -1);
+        LOGERROR("Execute Lua function failed: " + String(message));
+        lua_settop(luaState, top);
+        return;
+    }
 }
 }
 
 
 }
 }

+ 11 - 11
Source/Extras/LuaScript/LuaScriptInstance.h

@@ -43,27 +43,27 @@ public:
     static void RegisterObject(Context* context);
     static void RegisterObject(Context* context);
 
 
     /// Create script object.
     /// Create script object.
-	bool CreateObject(const String& objectType);
+    bool CreateObject(const String& objectType);
 
 
-	/// Script subscribe event.
-	void ScriptSubscribeToEvent(const String& eventName, const String& functionName);
+    /// Script subscribe event.
+    void ScriptSubscribeToEvent(const String& eventName, const String& functionName);
 
 
 protected:
 protected:
-	/// Push script object on stack.
-	bool PushScriptObject(lua_State* luaState);
+    /// Push script object on stack.
+    bool PushScriptObject(lua_State* luaState);
 
 
-	/// Handle event.
-	void HandleEvent(StringHash eventType, VariantMap& eventData);
+    /// Handle event.
+    void HandleEvent(StringHash eventType, VariantMap& eventData);
 
 
-	/// Call event handler.
-	void CallEventHandler(const String& functionName, StringHash eventType, VariantMap& eventData);
+    /// Call event handler.
+    void CallEventHandler(const String& functionName, StringHash eventType, VariantMap& eventData);
 
 
 private:
 private:
     /// Object type.
     /// Object type.
     String objectType_;
     String objectType_;
 
 
-	/// Event type to function name map.
-	HashMap<StringHash, HashSet<String> > eventTypeToFunctionNameMap_;
+    /// Event type to function name map.
+    HashMap<StringHash, HashSet<String> > eventTypeToFunctionNameMap_;
 };
 };
 
 
 }
 }