-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent definitions of constants? #75
Comments
It appears that this might be a WIP based on this? 369240c |
Sorry for the late reply. I missed this message.
There are some exceptions for the non-direct translation for constants like flex parameters. I was considering to follow css style. The color is another example, so we can set color directly using
But I agree with you too. Use the straightforward translation of LVGL constants minimize the learning cost. So I agree to keep both methods.
This PR is to reduce RAM usage by moving the contants in lua to flash. |
Yes, I've noticed that, pretty elegant.
Understood, this can make sense. I was referring to code where it is just doing set of sequential "strcmp" commands, to return a single LVGL constant--this does not make any sense. Anyway, I have been making huge modifications to the project, adding support for the rest of the LVGL widgets. (I have done some fundamental revamps, particularly with the build system. Only ".h" files are #included now; ".c" files should be handled by the makefile--same as LVGL and Lua for that matter). Once I get all the widget support completed, is this something you would like to continue on this repo, or should I host it separately? |
That can be optimized using similar methods to other LVGL constants. I haven't got time to refine it yet.
I got the idea from luv(libuv lua binding). But using LVGL's style is OK too.
It would be great if you could contribute to this repo. I had been discussing to host this repo under LVGL, so more developers can benefit from it. #49 There's issue #69 needs to be addressed firstly.
If possible, could you send the code in batches for review? |
It's such a fundamental revamp that I'm not sure "batching" is going to be feasible. With the changes, plus adding all of the other LVGL widgets...the "src" folder has gone from the original 236KB to a current 381KB. The main problem with #including C source files, is the inherent sequential inheritance. Dependency circles can very quickly turn into an impossible quagmire--which is why guarded C header files are generally used for interconnection of multiple source files. |
Introduce the problem
It appears to me that some LVGL constants are bound to the Lua interface as integers, and others are bound as strings.
From the example provided in the main page of the repository:
Notice that all the "flex" properties are set as strings.
Meanwhile, the "align" (next to last line) is set as a named constant.
I can perhaps see where use of strings could have an advantage in cases where multiple LVGL constants can be "stacked together" as flags for a specific outcome. However, when the constants are part of a sequential enum (i.e. not "binary stackable flags"), use of strings seems rather odd.
Another potential usecase could stem from trying to differentiate between multiple different constants with the same name, e.g. "center"--although there should be ways around that, e.g. "lvgl.FLEX_ALIGN.CENTER". Possibly harder would be getting the linter to suggest from "FLEX_ALIGN" on those properties over just "ALIGN"...?
In source, here is where the "align" constants are defined:
luavgl/src/constants.c
Lines 125 to 150 in d25acfb
It's a nice and straightforward dictionary of integers, linked to Lua here:
luavgl/src/constants.c
Lines 612 to 619 in d25acfb
callback assigned here:
luavgl/src/obj.c
Lines 872 to 878 in d25acfb
and easily handled on the receiving end here:
luavgl/src/obj.c
Lines 803 to 811 in d25acfb
(code goes on further to allow other entries as well for more specific aligning if a Lua table is provided)
Conversely, in "luavgl_to_flex_align" (among several others), it's just a list of sequential strcmps with the goal of getting the corresponding integer constant:
luavgl/src/style.c
Lines 196 to 221 in d25acfb
Note that with "flex_direction", strstr is used to allow "-reverse" as a flag keyword; however, as there are only 4 options, I still think this would better be handled with an integer constant. Besides, Lua allows adding together defined values:
luavgl/src/style.c
Lines 256 to 274 in d25acfb
All that to say...I am not well versed in Lua, so I could be missing something obvious.
But: Is there a specific reason for the use of strings when binding LVGL constants to Lua?
Proposal
Port all "strcmp" sequential argument parsing to named constants?
The text was updated successfully, but these errors were encountered: