Tockra Posted August 30, 2011 Share Posted August 30, 2011 Hey Guys, I want get the origin of a function call to output it in a debugscript! Im using this little function: function MySQL_Save ( strings ) return mysql_escape_string ( Datenbank, strings ) end But if i call this function by a wrong parameter i get the error every time in this line: "return mysql_escape_string ( Datenbank, strings )" and i dont know where the origin of the error is... Link to comment
SDK Posted August 30, 2011 Share Posted August 30, 2011 This should be in the scripting forum. Anyway, you can add a check and then use your own error output in debug. Example: function MySQL_Save ( strings ) if not strings then outputDebugString("MySQL_Save: no argument", 3) return false elseif type(strings) ~= 'string' then outputDebugString("MySQL_Save: arg #1 not a string", 3) return false elseif #strings < 1 then outputDebugString("MySQL_Save: invalid string", 3) return false end return mysql_escape_string ( Datenbank, strings ) end You can find an advanced function for argument checking here: https://wiki.multitheftauto.com/wiki/Check Link to comment
Tockra Posted August 30, 2011 Author Share Posted August 30, 2011 This should be in the scripting forum.Anyway, you can add a check and then use your own error output in debug. Example: function MySQL_Save ( strings ) if not strings then outputDebugString("MySQL_Save: no argument", 3) return false elseif type(strings) ~= 'string' then outputDebugString("MySQL_Save: arg #1 not a string", 3) return false elseif #strings < 1 then outputDebugString("MySQL_Save: invalid string", 3) return false end return mysql_escape_string ( Datenbank, strings ) end You can find an advanced function for argument checking here: https://wiki.multitheftauto.com/wiki/Check Yeah i know these functions... But here you have an example: function test() thefunction("huhu") -- here i want a error end addCommandHandler("test",test) function thefunction(int) if(type(int) == "string") then outputDebugString("Don't use Strings!", 3) -- I get the Error in this line, but i want it in this line : "thefunction("huhu")" . I dont know here where the function was called... end end Link to comment
SDK Posted August 30, 2011 Share Posted August 30, 2011 Take a look at the error() function then: http://www.lua.org/manual/5.1/manual.html#pdf-error function test1(i) test2(i) end function test2(i) error("Don't use Strings!", i) end test1(1) -- Error: [string "function test1(i)..."] Don't use Strings! test1(2) -- Error: [string "function test1(i)..."] Don't use Strings! Link to comment
Recommended Posts