diff options
author | Paul Gilbert | 2010-08-05 10:16:21 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2010-10-12 22:23:24 +0000 |
commit | 49ea23c532cb0d8ab6e27d290484a1e2daadb347 (patch) | |
tree | 97dff77ee4deeb81f600288d30abb3413300180f /engines/sword25/input | |
parent | 1e3b3af5c09ef5b9168436b2276bce612f74c0d2 (diff) | |
download | scummvm-rg350-49ea23c532cb0d8ab6e27d290484a1e2daadb347.tar.gz scummvm-rg350-49ea23c532cb0d8ab6e27d290484a1e2daadb347.tar.bz2 scummvm-rg350-49ea23c532cb0d8ab6e27d290484a1e2daadb347.zip |
SWORD25: Fix for void * conversion errors
It turns out that strict C++ doesn't allow function pointers to be converted to void pointers and vice versa. Since there are two callback function pointer types - one with a KEY_COMMANDS enum parameter, and the other with an unsigned char type, I changed all void * occurances to a function pointer type with an 'int' parameter, and changed all implementation methods to take in an int parameter.
svn-id: r53208
Diffstat (limited to 'engines/sword25/input')
-rw-r--r-- | engines/sword25/input/inputengine.h | 11 | ||||
-rw-r--r-- | engines/sword25/input/inputengine_script.cpp | 21 | ||||
-rw-r--r-- | engines/sword25/input/scummvminput.h | 8 |
3 files changed, 19 insertions, 21 deletions
diff --git a/engines/sword25/input/inputengine.h b/engines/sword25/input/inputengine.h index 3cd1ce6e3f..f88f67de38 100644 --- a/engines/sword25/input/inputengine.h +++ b/engines/sword25/input/inputengine.h @@ -49,6 +49,7 @@ #include "sword25/kernel/common.h" #include "sword25/kernel/service.h" #include "sword25/kernel/persistable.h" +#include "sword25/kernel/callbackregistry.h" namespace Sword25 { @@ -254,7 +255,7 @@ public: */ virtual bool WasKeyDown(unsigned int KeyCode) = 0; - typedef void (*CharacterCallback)(unsigned char Character); + typedef CallbackPtr CharacterCallback; /** * Registers a callback function for keyboard input. @@ -268,15 +269,15 @@ public: * The input of strings by the user through use of callbacks should be implemented. * @return Returns true if the function was registered, otherwise false. */ - virtual bool RegisterCharacterCallback(CharacterCallback Callback) = 0; + virtual bool RegisterCharacterCallback(CallbackPtr Callback) = 0; /** * De-registeres a previously registered callback function. * @return Returns true if the function could be de-registered, otherwise false. */ - virtual bool UnregisterCharacterCallback(CharacterCallback Callback) = 0; + virtual bool UnregisterCharacterCallback(CallbackPtr Callback) = 0; - typedef void (*CommandCallback)(KEY_COMMANDS Command); + typedef CallbackPtr CommandCallback; /** * Registers a callback function for the input of commands that can have influence on the string input @@ -287,7 +288,7 @@ public: * The input of strings by the user through the use of callbacks should be implemented. * @return Returns true if the function was registered, otherwise false. */ - virtual bool RegisterCommandCallback(CommandCallback Callback) = 0; + virtual bool RegisterCommandCallback(CallbackPtr Callback) = 0; /** * Un-register a callback function for the input of commands that can have an influence on the string input. diff --git a/engines/sword25/input/inputengine_script.cpp b/engines/sword25/input/inputengine_script.cpp index 0580caa983..a7bd39481b 100644 --- a/engines/sword25/input/inputengine_script.cpp +++ b/engines/sword25/input/inputengine_script.cpp @@ -57,8 +57,8 @@ using namespace Lua; // Callback-Objekte // ----------------------------------------------------------------------------- -static void TheCharacterCallback(unsigned char Character); -static void TheCommandCallback(BS_InputEngine::KEY_COMMANDS Command); +static void TheCharacterCallback(int Character); +static void TheCommandCallback(int Command); namespace { class CharacterCallbackClass : public BS_LuaCallback { @@ -68,8 +68,7 @@ namespace { Common::String Character; protected: - int PreFunctionInvokation(lua_State *L) - { + int PreFunctionInvokation(lua_State *L) { lua_pushstring(L, Character.c_str()); return 1; } @@ -242,8 +241,8 @@ static int SetMouseY(lua_State *L) { // ----------------------------------------------------------------------------- -static void TheCharacterCallback(unsigned char Character) { - CharacterCallbackPtr->Character = Character; +static void TheCharacterCallback(int Character) { + CharacterCallbackPtr->Character = static_cast<unsigned char>(Character); lua_State *L = static_cast<lua_State *>(BS_Kernel::GetInstance()->GetScript()->GetScriptObject()); CharacterCallbackPtr->InvokeCallbackFunctions(L, 1); } @@ -268,8 +267,8 @@ static int UnregisterCharacterCallback(lua_State *L) { // ----------------------------------------------------------------------------- -static void TheCommandCallback(BS_InputEngine::KEY_COMMANDS Command) { - CommandCallbackPtr->Command = Command; +static void TheCommandCallback(int Command) { + CommandCallbackPtr->Command = static_cast<BS_InputEngine::KEY_COMMANDS>(Command); lua_State *L = static_cast<lua_State *>(BS_Kernel::GetInstance()->GetScript()->GetScriptObject()); CommandCallbackPtr->InvokeCallbackFunctions(L, 1); } @@ -345,10 +344,8 @@ bool BS_InputEngine::_RegisterScriptBindings() { if (!BS_LuaBindhelper::AddFunctionsToLib(L, PACKAGE_LIBRARY_NAME, PACKAGE_FUNCTIONS)) return false; if (!BS_LuaBindhelper::AddConstantsToLib(L, PACKAGE_LIBRARY_NAME, PACKAGE_CONSTANTS)) return false; - Common::SharedPtr<CharacterCallbackClass> p1(new CharacterCallbackClass(L)); - CharacterCallbackPtr = p1; - Common::SharedPtr<CharacterCallbackClass> p2(new CommandCallbackClass(L)); - CommandCallbackPtr = p2; + CharacterCallbackPtr = Common::SharedPtr<CharacterCallbackClass>(new CharacterCallbackClass(L)); + CommandCallbackPtr = Common::SharedPtr<CommandCallbackClass>(new CommandCallbackClass(L)); return true; } diff --git a/engines/sword25/input/scummvminput.h b/engines/sword25/input/scummvminput.h index a26060f4ab..b38a54b757 100644 --- a/engines/sword25/input/scummvminput.h +++ b/engines/sword25/input/scummvminput.h @@ -65,10 +65,10 @@ public: virtual bool WasKeyDown(unsigned int KeyCode); virtual void SetMouseX(int PosX); virtual void SetMouseY(int PosY); - virtual bool RegisterCharacterCallback(CharacterCallback Callback); - virtual bool UnregisterCharacterCallback(CharacterCallback Callback); - virtual bool RegisterCommandCallback(CommandCallback Callback); - virtual bool UnregisterCommandCallback(CommandCallback Callback); + virtual bool RegisterCharacterCallback(CallbackPtr Callback); + virtual bool UnregisterCharacterCallback(CallbackPtr Callback); + virtual bool RegisterCommandCallback(CallbackPtr Callback); + virtual bool UnregisterCommandCallback(CallbackPtr Callback); virtual void ReportCharacter(unsigned char Character); virtual void ReportCommand(KEY_COMMANDS Command); |