Differences between WattleScript Lua and Lua
WattleScript’s Lua mode contains minor differences and a few additions, inherited from MoonSharp.
List of Differences
- Strings are Unicode: some caution is required if code uses strings to store binary data. On the other hand, strings used as real strings are a lot easier to use.
- Garbage Collection is different, as WattleScript makes use of the .NET GC. Notably this makes
collectgarbage()a no-op. - Compatibility is source-only, WattleScript cannot load luac binaries.
- Slight differences in error messages.
- Function names are tracked at function declaration, not backtracked at function calls like in Lua (noticeable only when debugging)
List of Additions
- Multiple expressions can be used as indices but the value to be indexed must be a userdata, or a table resolving to userdata through the metatable (but without using metamethods). So, for example,
x[1,2,i]is parsed correctly but might raise an error ifxis not a userdata. - Metalua short anonymous functions (lambda-style) are supported. So
|x, y| x + yis shorthand forfunction(x,y) return x+y end. - A non-yieldable
__iteratormetamethod has been added. It’s called if the argumentfof afor ... in ...loop is not actually a function. - A default iterator is provided if the argument
fof afor ... in ...loop is a table without__iteratoror__callmetamethods. The provided result isvalue, keyunlikeipairsorpairs. \u{xxx}escapes, where x are up to 8 hexadecimal digits, are supported inside strings and will output the specified Unicode codepoint, as it does in Lua 5.3loadsafeandloadfilesafemethods, same asloadandloadfilebut defaulting to the current top-of-the-stack_ENVinstead of the default one, for easier sandboxing- The
dynamic.evalanddynamic.preparefunctions to handle dynamic expressions string.unicodemethod, just likestring.bytebut returning a whole unicode codepointstring.contains,string.startsWithandstring.endsWithmethods allow easier and faster performing string ops without having to rely on patterns for simple scenarios- The
jsonmodule to support JSON<->table conversions