1
1
Object . assign ( pc , function ( ) {
2
- var funcNameRegex = new RegExp ( '^\\s*function(?:\\s|\\s*\\/\\*.*\\*\\/\\s*)+([^\\(\\s\\/]*)\\s*' ) ;
3
-
4
- var _getFuncName = function ( func ) {
5
- if ( typeof func !== 'function' ) return undefined ;
6
- if ( 'name' in Function . prototype ) return func . name ;
7
- if ( func === Function || func === Function . prototype . constructor ) return 'Function' ;
8
- var match = ( "" + func ) . match ( funcNameRegex ) ;
9
- return match ? match [ 1 ] : undefined ;
10
- } ;
11
-
12
2
/* eslint-disable jsdoc/no-undefined-types */
13
3
/**
14
4
* @static
@@ -100,6 +90,9 @@ Object.assign(pc, function () {
100
90
*
101
91
* // register the class as a script
102
92
* pc.registerScript(PlayerController);
93
+ *
94
+ * // declare script attributes (Must be after pc.registerScript())
95
+ * PlayerController.attributes.add('attribute1', {type: 'number'});
103
96
*/
104
97
/* eslint-enable jsdoc/check-examples */
105
98
/* eslint-enable jsdoc/no-undefined-types */
@@ -115,9 +108,9 @@ Object.assign(pc, function () {
115
108
throw new Error ( 'script class: \'' + script + '\' must be a constructor function (i.e. class).' ) ;
116
109
117
110
if ( ! ( script . prototype instanceof pc . ScriptType ) )
118
- throw new Error ( 'script class: \'' + _getFuncName ( script ) + '\' does not extend pc.ScriptType.' ) ;
111
+ throw new Error ( 'script class: \'' + pc . ScriptType . __getScriptName ( script ) + '\' does not extend pc.ScriptType.' ) ;
119
112
120
- name = name || script . __name || _getFuncName ( script ) ;
113
+ name = name || script . __name || pc . ScriptType . __getScriptName ( script ) ;
121
114
122
115
if ( createScript . reservedScripts [ name ] )
123
116
throw new Error ( 'script name: \'' + name + '\' is reserved, please change script name' ) ;
0 commit comments