Jump to content

Origin of a function call


Recommended Posts

Posted

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...

h32yhix1ossu.png
Posted

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

Learn Lua - Learn to script - GUI scripting

Scripter tools - Find/fix errors yourself(!)

Don't pm me for scripting help, keep it for the Scripting subforum!

Posted
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 
  

h32yhix1ossu.png
Posted

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! 

Learn Lua - Learn to script - GUI scripting

Scripter tools - Find/fix errors yourself(!)

Don't pm me for scripting help, keep it for the Scripting subforum!

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...