PageRenderTime 3ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/visualizations/Vortex/angelscript/docs/doxygen/source/doc_good_practice.h

http://github.com/xbmc/xbmc
C++ Header | 42 lines | 0 code | 0 blank | 42 comment | 0 complexity | d27c4b76f4e77522396c626fadf0cc52 MD5 | raw file
 1/**
 2
 3\page doc_good_practice Good practices
 4
 5
 6This article will try to explain some good practices, that will help you get going faster and easier find the solution when a problem occurs.
 7
 8\section doc_checkretval Always check return values for registrations
 9
10
11When configuring the script engine you should always check the return values, at least in debug mode. 
12All error codes are negative so a simple <code>assert( r >= 0 )</code> where r is the returned value is sufficient 
13to pinpoint where the configuration failed.
14
15
16If a function failed during the configuration, the \ref asIScriptModule::Build "Build" method will always fail with a return code 
17of \ref asINVALID_CONFIGURATION. Unless you already verified the error codes for all the configuration 
18calls, it will not be possible to determine what the error was.
19
20\code
21// Verifying the return code with an assert is simple and won't pollute the code
22r = engine->RegisterGlobalFunction("void func()", asFUNCTION(func), asCALL_CDECL); assert( r >= 0 );
23\endcode
24
25<code>assert()</code> can safely be used with engine registrations, since the engine will set the internal state 
26to invalid configuration if a function fails. Even in release mode the failure is discovered when 
27a script is built.
28
29\section doc_usemsgcallbck Use the message callback to receive detailed error messages
30
31The return code from the register functions, \ref asIScriptModule::Build "Build", and 
32\ref asIScriptModule::CompileFunction "CompileFunction", can only tell you that something was wrong, 
33not what it was. To help identify the exact problem the message callback should be used. The script 
34library will then send messages explaining the error or warning in clear text.
35
36See \ref doc_compile_script_msg for more information on the message callback.
37
38
39
40
41
42*/