Comments (4)
there may be no problem parsing parent in patterns in your example code.
u8 mip[123] [[name(std::format("mip{}", parent.i))]]
the problem here is that the name attribute adds another level to parent. To access i you need to use parent.parent.i and it works fine.
parent.i += 1;
whatever the problem is with this, it has nothing to do with parent. in general any statement like (any name).(any member)=(any value) inside a struct will give the same error. In this case accessing i in from the parent to increment it is completely unnecessary as it can be incremented in its own structure using i+=1. (btw, using hidden in a local variable has no effect since local variables are always hidden)
from imhex.
I looked at your code in more detail and realized that you were trying to use i as an indication of the current array index. ImHex has a special function that returns the current array index in std::core::array_index(). with a small modification to your previous posted pattern (that tried to create an array of negative size) I was able to read the entire input file using the following changes:
in ImageMip
u8 mip[parent.mipInfos[parent.i+std::core::array_index()].decompressedSize] [[name(std::format("mip{}", parent.parent.i+std::core::array_index()))]];
in Image
ImageMip mip[header.mipCount - header.streamDBMipCount];
this way i doesn't need to be updated since it can't be updated from the child which is why array_index function was created for.
from imhex.
[...]
u8 mip[123] [[name(std::format("mip{}", parent.i))]]
the problem here is that the name attribute adds another level to parent. To access i you need to use parent.parent.i and it works fine. [...]
I guess that that makes sense (especially for this
pointing to the currently-being-made pattern/variable), but it feels odd considering that u8 x = 10; u8 mip[123] [[name(std::format("mip{}", x))]];
doesn't need parent.
to access the x
next to it.
Seeing as you don't need parent.
in attributes when referencing other patterns/variables in the same struct, the first parent.
"layer" is essentially useless*; it might be more intuitive if the Pattern Language automatically "adds" an extra parent.
layer within attributes (so that parent.var
refers to the same thing both inside and outside of attributes).
* If you specifically want to refer to the struct containing the pattern/variable currently being created, then this.parent
should work, so there won't be any lost functionality by auto-adding an extra parent.
layer.
[...]
parent.i += 1;
whatever the problem is with this, it has nothing to do with parent. in general any statement like (any name).(any member)=(any value) inside a struct will give the same error. [...]
I found that out later: WerWolv/PatternLanguage#87
But worth noting: Due to the "you need an extra parent.
in attributes" thing above, plus WerWolv telling me that parent
might not be parsed correctly (and telling me to make this GitHub issue about it), I thought that parent
was just a little iffy in general.
[...] ImHex has a special function that returns the current array index in std::core::array_index(). [...]
I've since edited my pattern file to use that (or more specifically u32 i = std::core::array_index() + parent.header.streamDBMipCount
within the ImageMip
struct, to use just i
later throughout the struct).
I just thought that it would've looked cleaner to do it like I was trying to do at first, considering that i
is supposed to start at a non-zero value here and std::core::array_index() + parent.header.streamDBMipCount
is somewhat of a "mess" to look at.
from imhex.
but it feels odd considering that u8 x = 10; u8 mip[123] [[name(std::format("mip{}", x))]]; doesn't need parent. to access the x next to it.
You are right that it doesn't need a parent there but note that it also works with parent.x equally well. I suspect that a parent layer is being skipped in the case of attributes referring to members of the parent struct, at least that's the only explanation I can think of of why it works with and without parent, considering how it needs two if the member is on the parent struct.
Don't get me wrong, I'm not saying that parent works as it should, I just don't see the problem in the example you posted. parent feature has been plagued with problems because it is a hard feature to implement. At one point creating arrays added a parent layer, but it looks like that's not the case anymore, so you may be right about it being fishy, but I still don't understand fully how it is supposed to work in reality to state that it is not working correctly.
std::core::array_index() + parent.header.streamDBMipCount
is somewhat of a "mess" to look at.
yes, I suppose it is. There are ways to make it look better (for example, in my version I use parent.i
instead of parent.header....) like writing a function or using a macro define, but in the end array_index() is the only way I know of to obtain a working current index and I tried lots of ways a while back.
from imhex.
Related Issues (20)
- [Bug] When working on more than one file, the patter editor ignores new settings HOT 2
- [Bug] fractional scaling doesn't work
- [Bug] Opening project, when other file/project is opened causes SegFault
- [Bug] Application freezes on startup after a crash HOT 4
- [[format_write]] is broken HOT 1
- [Feature] Human-readable (user-facing) only output in pattern view
- [Bug] `[[hidden]]` values being shown in value summary for struct HOT 4
- [Feature] Make Enter enter ASCII editing mode instead of hex editing mode if ASCII column is selected
- [Bug] Imhex freezes when the scaling isnt native HOT 1
- [Bug] Imhex scaling issue at 1080 1.5x HOT 2
- [Bug] Achievements dont save
- [Bug] Maximizing the window maxes it freeze for a split second
- [Feature] Change the Differ's bottom section's height by just dragging up or down
- [Feature] Please include row width as part of a layout.
- [Bug] Bug in pattern leaves ImHex in corrupted state, program reload required, no pattern reload (with corrected pattern) can fix this. HOT 2
- [Feature] [PL] Make [hidden] a conditional attribute HOT 1
- [Feature] Plot of field values in a multi-record file HOT 1
- [Hub] Artifact and cache size HOT 3
- [Bug] #endif is considered an invalid directive if anything is on the immediate line after HOT 1
- [Bug] #pragma eval_depth is nonfunctional and seemingly ignored by the compiler HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imhex.