@@ -238,26 +238,47 @@ public LuaChunk CompileChunk(string code, string name, LuaCompileOptions options
238
238
return CompileChunkCore ( lex , options , args ) ;
239
239
} // func CompileChunk
240
240
241
+ /// <summary>Create a code delegate without executing it.</summary>
242
+ /// <param name="code">Code of the delegate..</param>
243
+ /// <param name="options">Options for the compile process.</param>
244
+ /// <param name="args">Arguments for the code block.</param>
245
+ /// <returns>Compiled chunk.</returns>
246
+ public LuaChunk CompileChunk ( ILuaLexer code , LuaCompileOptions options , params KeyValuePair < string , Type > [ ] args )
247
+ {
248
+ if ( code == null )
249
+ throw new ArgumentNullException ( nameof ( code ) ) ;
250
+ return CompileChunkCore ( code , options , args ) ;
251
+ } // func CompileChunk
252
+
241
253
/// <summary>Creates a code delegate or returns a single return constant.</summary>
242
254
/// <param name="code"></param>
243
255
/// <param name="options"></param>
244
256
/// <param name="args"></param>
245
257
/// <returns></returns>
246
- public object CompileOrReturnConstant ( ILuaLexer code , LuaCompileOptions options , params KeyValuePair < string , Type > [ ] args )
258
+ public object CompileOrReturnPrint ( ILuaLexer code , LuaCompileOptions options , params KeyValuePair < string , Type > [ ] args )
247
259
{
248
- code . Next ( ) ; // get first token
249
-
250
- if ( code . Current . Typ == LuaToken . KwReturn // is first token a return
251
- && ( code . LookAhead . Typ == LuaToken . String || code . LookAhead . Typ == LuaToken . Number ) // we expect a string or number
252
- && ( code . LookAhead2 . Typ == LuaToken . Semicolon || code . LookAhead2 . Typ == LuaToken . Eof ) ) // eof
260
+ if ( IsConstantScript ( code ) ) // eof
253
261
{
254
262
return code . LookAhead . Typ == LuaToken . String
255
263
? code . LookAhead . Value
256
- : RtParseNumber ( code . LookAhead . Value , FloatType == LuaFloatType . Double ) ;
264
+ : ParseNumber ( code . LookAhead . Value ) ;
257
265
}
258
266
else
259
267
return CompileChunkCore ( code , options , args ) ;
260
- } // func CompileOrReturnConstant
268
+ } // func CompileOrReturnPrint
269
+
270
+ /// <summary>Test for single print expression.</summary>
271
+ /// <param name="code"></param>
272
+ /// <returns></returns>
273
+ public static bool IsConstantScript ( ILuaLexer code )
274
+ {
275
+ if ( code . Current == null )
276
+ code . Next ( ) ;
277
+
278
+ return ( code . Current . Typ == LuaToken . Identifier && code . Current . Value == "print" ) // is first token is print
279
+ && ( code . LookAhead . Typ == LuaToken . String || code . LookAhead . Typ == LuaToken . Number ) // we expect a string or number
280
+ && ( code . LookAhead2 . Typ == LuaToken . Eof ) ;
281
+ } // func IsConstantScript
261
282
262
283
internal LuaChunk CompileChunkCore ( ILuaLexer lex , LuaCompileOptions options , IEnumerable < KeyValuePair < string , Type > > args )
263
284
{
@@ -381,10 +402,10 @@ public object ParseNumber(string number)
381
402
382
403
/// <summary>Parses a string to a lua number.</summary>
383
404
/// <param name="number">String representation of the number.</param>
384
- /// <param name="iBase ">Base fore the number</param>
405
+ /// <param name="toBase ">Base fore the number</param>
385
406
/// <returns></returns>
386
- public object ParseNumber ( string number , int iBase )
387
- => RtParseNumber ( null , number , 0 , iBase , FloatType == LuaFloatType . Double , false ) ;
407
+ public object ParseNumber ( string number , int toBase )
408
+ => RtParseNumber ( null , number , 0 , toBase , FloatType == LuaFloatType . Double , false ) ;
388
409
389
410
internal int NumberType => numberType ;
390
411
0 commit comments