Closed danhowardgames closed 2 years ago
@chowyunbrent I have a guess as to what's going on: the sprites
property of sinfo
is being recognized as a symbol and thus minified to fy
. This works only if the sprites property is always assigned using dot notation, so that every sprites
is replaced with fy
. I bet that somewhere else in your code, you refer to the sprites
property with string index notation, which it doesn't know to minify. Am I right?
test = {}
test['foo'] = 123
print(test.foo)
minifies to:
a={}
a['foo']=123
print(a.b)
which is wrong. The correct behavior is probably to never minify property names, which is a minor loss but the only way to assure correctness.
If you can, you can work around this using dot notation everywhere:
test = {}
test.foo = 123
print(test.foo)
Table initializer syntax is also unaffected:
test = {foo=123}
print(test.foo)
minifies correctly to:
a={b=123}
print(a.b)
Hi! Thank you so much for getting back to me.
Yes i think you are right... but it looks like its the e.spr_info[e.state] that uses e.state as string index notation (the state name e.g. "idle"). I'll have a go at rewriting it and try again.
Thanks for your help Dan!
Ah yes, if e.spr_info is defined elsewhere using dot or table initializer syntax, then e.state will be "idle" but the actual state name will be minified. You can change where that is initialized to use strings: e.spr_info["idle"] = ... and it should work.
I'm leaving this issue open because the tool should really account for this. Thanks for the report!
You may want to try my pull request. It addresses this specific issue and may fix your problem.
luamin now has --keep-names-from-file= for project-specific property name preservation (or just working around my delays in adding new built-ins), as well as --keep-all-names to restrict minification to comments and whitespace.
I've decided not to support a luamin flag that exempts all properties. Any project that refers to the same property with dot notation and index notation is already dealing with a fixed quantity of properties that the author can put in a file. It's a bit more to ask of authors that are doing this, but I feel like it's enough of a solution and there's not enough added benefit to fully implement something that exempts all property names and nothing else.
I suspect its something to do with the renaming of table indexes but im not sure!
The error in question is here, but it appears in other sectons if i comment this out.
original:
minified:
i'm happy to send you the full code if that helps find the error?
Thanks