Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.0 KiB

  1. //========== Copyright � 2008, Valve Corporation, All rights reserved. ========
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. function UniqueString( string = "" )
  7. {
  8. return DoUniqueString( string.tostring() );
  9. }
  10. function EntFire( target, action, value = null, delay = 0.0, activator = null )
  11. {
  12. if ( !value )
  13. {
  14. value = "";
  15. }
  16. local caller = null;
  17. if ( "self" in this )
  18. {
  19. caller = self;
  20. if ( !activator )
  21. {
  22. activator = self;
  23. }
  24. }
  25. DoEntFire( target.tostring(), action.tostring(), value.tostring(), delay, activator, caller );
  26. }
  27. function __ReplaceClosures( script, scope )
  28. {
  29. if ( !scope )
  30. {
  31. scope = getroottable();
  32. }
  33. local tempParent = { getroottable = function() { return null; } };
  34. local temp = { runscript = script };
  35. delegate tempParent : temp;
  36. temp.runscript()
  37. foreach( key,val in temp )
  38. {
  39. if ( typeof(val) == "function" && key != "runscript" )
  40. {
  41. printl( " Replacing " + key );
  42. scope[key] <- val;
  43. }
  44. }
  45. }
  46. /*
  47. UNDONE FOR PORTAL2 BRANCH:
  48. We're not suing the auto-connecting of outputs, always calling ConnectOuput explicitly in our scripts.
  49. The regexp object doesn't save/load properly and causes a crash when used to match after a save/load.
  50. Instead of fixing this, we're disabling the feature. If this class of problem comes up more we might
  51. revisit, otherwise we'll leave if off and broken.
  52. __OutputsPattern <- regexp("^On.*Output$");
  53. function ConnectOutputs( table )
  54. {
  55. const nCharsToStrip = 6;
  56. foreach( key, val in table )
  57. {
  58. if ( typeof( val ) == "function" && __OutputsPattern.match( key ) )
  59. {
  60. //printl(key.slice( 0, nCharsToStrip ) );
  61. table.self.ConnectOutput( key.slice( 0, key.len() - nCharsToStrip ), key );
  62. }
  63. }
  64. }
  65. */
  66. function IncludeScript( name, scope = null )
  67. {
  68. if ( scope == null )
  69. {
  70. scope = this;
  71. }
  72. return ::DoIncludeScript( name, scope );
  73. }
  74. //---------------------------------------------------------
  75. // Text dump this scope's contents to the console.
  76. //---------------------------------------------------------
  77. function __DumpScope( depth, table )
  78. {
  79. local indent=function( count )
  80. {
  81. local i;
  82. for( i = 0 ; i < count ; i++ )
  83. {
  84. print(" ");
  85. }
  86. }
  87. foreach(key, value in table)
  88. {
  89. indent(depth);
  90. print( key );
  91. switch (type(value))
  92. {
  93. case "table":
  94. print("(TABLE)\n");
  95. indent(depth);
  96. print("{\n");
  97. __DumpScope( depth + 1, value);
  98. indent(depth);
  99. print("}");
  100. break;
  101. case "array":
  102. print("(ARRAY)\n");
  103. indent(depth);
  104. print("[\n")
  105. __DumpScope( depth + 1, value);
  106. indent(depth);
  107. print("]");
  108. break;
  109. case "string":
  110. print(" = \"");
  111. print(value);
  112. print("\"");
  113. break;
  114. default:
  115. print(" = ");
  116. print(value);
  117. break;
  118. }
  119. print("\n");
  120. }
  121. }