11import {
22 NamedVarOpType ,
3+ SLua ,
34 SLuaBaseType ,
45 SLuaClassDef ,
56 SLuaCustomType ,
@@ -177,11 +178,13 @@ export function isSimpleTypeValue(s: string): s is SLuaSimpleTypeValue {
177178export function generatePreferedCodeSample (
178179 prefix : string [ ] ,
179180 func : SLuaFuncDef ,
181+ slua : SLua ,
180182) : [ string , number ] {
181183 let str = generateCodeSample (
182184 prefix ,
183185 func ,
184186 0 ,
187+ slua ,
185188 0 ,
186189 func . signatures [ 0 ] . args . length > 3 ,
187190 ) ;
@@ -193,6 +196,7 @@ export function generatePreferedCodeSample(
193196 prefix ,
194197 func ,
195198 i ,
199+ slua ,
196200 o ,
197201 func . signatures [ i ] . args . length > 3 ,
198202 ) ;
@@ -211,6 +215,7 @@ export function generateCodeSample(
211215 prefix : string [ ] ,
212216 func : SLuaFuncDef ,
213217 sigIndex : number ,
218+ slua : SLua ,
214219 off : number = 0 ,
215220 verbose : boolean = false ,
216221) : string {
@@ -221,6 +226,7 @@ export function generateCodeSample(
221226 off ,
222227 verbose ,
223228 func . takesSelf ,
229+ slua ,
224230 ) ;
225231}
226232
@@ -236,8 +242,14 @@ function generateCodeSampleForSig(
236242 off : number = 0 ,
237243 verbose : boolean = false ,
238244 takesSelf : boolean = false ,
245+ slua : SLua ,
239246) : string {
240- const [ args , funcs ] = buildCodeSampleArgsForSig ( sig . args , off , verbose ) ;
247+ const [ args , funcs ] = buildCodeSampleArgsForSig (
248+ sig . args ,
249+ off ,
250+ verbose ,
251+ slua ,
252+ ) ;
241253 if ( takesSelf ) args . shift ( ) ;
242254 const prefix = funcs . length > 0 ? funcs . join ( "\n\n" ) + "\n\n" : "" ;
243255 if ( verbose ) {
@@ -251,13 +263,47 @@ function buildCodeSampleArgsForSig(
251263 fargs : SLuaFuncArgs ,
252264 off : number ,
253265 verbose : boolean = false ,
266+ slua : SLua ,
254267) : [ string [ ] , string [ ] ] {
255268 const args : ( string | null ) [ ] = [ ] ;
256269 const funcs : string [ ] = [ ] ;
257270 for ( const arg of fargs ) {
258271 const type = cleanType ( arg . type , off ) ;
259272 switch ( type . def ) {
260- case "custom" :
273+ case "custom" : {
274+ const custom = slua . types [ type . value ] ;
275+ if ( custom ) {
276+ let ctype = custom . type ;
277+ if ( ctype instanceof Array ) {
278+ ctype = ctype [ 0 ] ;
279+ }
280+ switch ( ctype . def ) {
281+ case "simple" :
282+ args . push (
283+ buildCodeSampleSimpleArgForSig ( ctype , verbose ) ,
284+ ) ;
285+ break ;
286+ case "value" :
287+ args . push ( ctype . value . toString ( ) ) ;
288+ break ;
289+ case "function" :
290+ funcs . push (
291+ generateCodeSampleForFunction (
292+ ctype . value ,
293+ arg . name ,
294+ ) ,
295+ ) ;
296+ args . push ( arg . name ) ;
297+ break ;
298+ default :
299+ args . push ( type . value . toString ( ) ) ;
300+ break ;
301+ }
302+ } else {
303+ args . push ( type . value . toString ( ) ) ;
304+ }
305+ break ;
306+ }
261307 case "value" :
262308 args . push ( type . value . toString ( ) ) ;
263309 break ;
@@ -318,6 +364,10 @@ function generateCodeSampleForFunction(
318364 if ( name ) {
319365 result += `local ${ name } = ` ;
320366 }
367+ sig = JSON . parse ( JSON . stringify ( sig ) ) ;
368+ for ( const arg of sig . args ) {
369+ if ( ! arg . name ) arg . name = "arg" ;
370+ }
321371 return `${ result } function(${
322372 mapArgsToFunctionParamString ( sig . args , true )
323373 } ) : ${ mapResultToFunctionString ( sig . result ) } \n -- Your code\nend`;
0 commit comments