dansanderson / picotool

Tools and Python libraries for manipulating Pico-8 game files. http://www.lexaloffle.com/pico-8.php
MIT License
367 stars 46 forks source link

Support for the Type() function in PICO-8? #20

Closed Liquidream closed 6 years ago

Liquidream commented 7 years ago

Hi,

It seems that luamin does not recognise the Type() function in PICO-8?

I use this function quite a lot and in the minified output, it seems to leave renamed function calls (e.g. ab() ), but there's never a definition of what ab is?

Let me know if you need any further information (or can't replicate!)

Thanks

dansanderson commented 7 years ago

Accepted. The fix is to add b'type' to this list: https://github.com/dansanderson/picotool/blob/master/pico8/lua/lexer.py#L24

Liquidream commented 7 years ago

Thanks for the suggested workaround.

Unfortunately, adding this appears produces the following error when I next run luamin: exp2 in binop at line 104 char 12

However, changing b'type' to b'foo' appears to be fine. So perhaps it's something about the word "type" that's the problem?

Hope this helps. 😃

dansanderson commented 7 years ago

In that case add it to: https://github.com/dansanderson/picotool/blob/master/pico8/lua/lua.py#L24

I think that other list expects the Lua parser to handle the keyword as part of the grammar. The Pico-8 builtins list are just used as reserved function and variable names that should not be minified. So even though type() is a Lua feature it's best thought of as a builtin. (Maybe a separate list of "Lua builtins" is called for.)

Liquidream commented 7 years ago

Yup, that did the trick! :smile: Thanks.

So... do you think this "separate list" idea would also be a solution to having a "do_not_minify" list (mentioned in another issue)?

You talked about using "externs" for that - so sounds like you were planning a diff/better way to implement?

dansanderson commented 6 years ago

Added type() to the core built-in list for luamin.