Skip to content
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

Feat environment variables #192

Merged
merged 5 commits into from
Jan 25, 2024
Merged

Feat environment variables #192

merged 5 commits into from
Jan 25, 2024

Conversation

Hyxogen
Copy link
Contributor

@Hyxogen Hyxogen commented Jan 8, 2024

Please note that this is not yet finished and just for early review

@Hyxogen Hyxogen requested a review from yuri91 January 8, 2024 16:04
@Hyxogen Hyxogen force-pushed the feat-env branch 4 times, most recently from 3824642 to 7f51d6b Compare January 10, 2024 12:15
@Hyxogen
Copy link
Contributor Author

Hyxogen commented Jan 10, 2024

This PR should be ready for review. This PR should not require the changes in cheerp-libs

@Hyxogen Hyxogen marked this pull request as ready for review January 10, 2024 12:25
Comment on lines 6264 to 6265
stream << "var " << EnvironName << "=[],";
stream << ArgvName << "=[];" << NewLine;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a 100% sure about this, as currently this is always emitted at the start of the file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, does it work when using a closure module? you probably have to use window/this/globalThis in that case to force the variables to be visible outside.

Also, maybe we could only have one variable, with two fields argv and env? but I don't have a good default name for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on a quick test, it seems like it also works for closure modules

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not work with a closure module or with no modules: you are defining the variables here, but really they should be defined from the outside, in the global scope, and you just use them here (checking that they exist).
I wrote a quick test, and if I just delete these lines altogether, it works. Otherwise, the content is always empty.

@Hyxogen Hyxogen added bug Something isn't working and removed bug Something isn't working labels Jan 11, 2024
@Hyxogen Hyxogen force-pushed the feat-env branch 3 times, most recently from a4d7de4 to ed3b767 Compare January 25, 2024 13:43
@Hyxogen Hyxogen requested a review from yuri91 January 25, 2024 13:45
@Hyxogen
Copy link
Contributor Author

Hyxogen commented Jan 25, 2024

The CheerpJ PR should be merged before this one

@Hyxogen
Copy link
Contributor Author

Hyxogen commented Jan 25, 2024

I didn't add the new builtins to the header as I didn't want to expose this to the average user, but they are now declared with the correct type in cheer-libs:
leaningtech/cheerp-libs#20

@Hyxogen
Copy link
Contributor Author

Hyxogen commented Jan 25, 2024

Also merge this PR last (i.e. cheerp-libs and cheerp-utils first)

@Hyxogen Hyxogen requested a review from yuri91 January 25, 2024 14:58
Emit global variables and their necessay initialization that can contain
program arguments/environment variables. These global variables are
string arrays.

Also add two builtins for internal use to get these globals:
const client::TArray<client::String>* __builtin_cheerp_environ(void);
const client::TArray<client::String>* __builtin_cheerp_argv(void);
This is no longer needed as environment variables are now natively
supported by Cheerp.
@yuri91 yuri91 merged commit 2e6c8f0 into master Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants