/xbmc/visualizations/Vortex/angelscript/docs/manual/doc_good_practice.html

http://github.com/xbmc/xbmc · HTML · 24 lines · 23 code · 0 blank · 1 comment · 0 complexity · 4aa5b37ec6ada1a7a424e3129c1caa5c MD5 · raw file

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  3. <title>AngelScript: Good practices</title>
  4. <link href="tabs.css" rel="stylesheet" type="text/css">
  5. <link href="doxygen.css" rel="stylesheet" type="text/css">
  6. </head><body>
  7. <!-- Generated by Doxygen 1.5.9 -->
  8. <div class="contents">
  9. <h1><a class="anchor" name="doc_good_practice">Good practices </a></h1>This article will try to explain some good practices, that will help you get going faster and easier find the solution when a problem occurs.<h2><a class="anchor" name="doc_checkretval">
  10. Always check return values for registrations</a></h2>
  11. When configuring the script engine you should always check the return values, at least in debug mode. All error codes are negative so a simple <code>assert( r &gt;= 0 )</code> where r is the returned value is sufficient to pinpoint where the configuration failed.<p>
  12. If a function failed during the configuration, the <a class="el" href="classas_i_script_module.html#8acf107194c5f079d7f7507309ebe613">Build</a> method will always fail with a return code of <a class="el" href="angelscript_8h.html#6e2a1647f02f2c5da931bab09e860f547416ebaf18f32e180595fb366a072754">asINVALID_CONFIGURATION</a>. Unless you already verified the error codes for all the configuration calls, it will not be possible to determine what the error was.<p>
  13. <div class="fragment"><pre class="fragment"><span class="comment">// Verifying the return code with an assert is simple and won't pollute the code</span>
  14. r = engine-&gt;<a class="code" href="classas_i_script_engine.html#754fafd069d8e0c19baff2dc222893b0" title="Registers a global function.">RegisterGlobalFunction</a>(<span class="stringliteral">"void func()"</span>, <a class="code" href="angelscript_8h.html#78f8f2c7f1c88b12e74a5ac47b4184ae" title="Returns an asSFuncPtr representing the function specified by the name.">asFUNCTION</a>(func), <a class="code" href="angelscript_8h.html#3ec92ea3c4762e44c2df788ceccdd1e468ae43cc91cdfc3fa4590c9e6164e4f4" title="A cdecl function.">asCALL_CDECL</a>); assert( r &gt;= 0 );
  15. </pre></div><p>
  16. <code>assert()</code> can safely be used with engine registrations, since the engine will set the internal state to invalid configuration if a function fails. Even in release mode the failure is discovered when a script is built.<h2><a class="anchor" name="doc_usemsgcallbck">
  17. Use the message callback to receive detailed error messages</a></h2>
  18. The return code from the register functions, <a class="el" href="classas_i_script_module.html#8acf107194c5f079d7f7507309ebe613">Build</a>, and <a class="el" href="classas_i_script_module.html#1258d7cfeed965f36ba312beeb49e81c">CompileFunction</a>, can only tell you that something was wrong, not what it was. To help identify the exact problem the message callback should be used. The script library will then send messages explaining the error or warning in clear text.<p>
  19. See <a class="el" href="doc_compile_script.html#doc_compile_script_msg">Message callback</a> for more information on the message callback. </div>
  20. <hr size="1"><address style="text-align: right;"><small>Generated on Wed Dec 16 19:34:50 2009 for AngelScript by&nbsp;
  21. <a href="http://www.doxygen.org/index.html">
  22. <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
  23. </body>
  24. </html>