amber-lang / amber

💎 Amber the programming language compiled to bash
https://amber-lang.com
GNU General Public License v3.0
3.8k stars 81 forks source link

[Feature] Call Amber function from Bash script #253

Open Mte90 opened 2 months ago

Mte90 commented 2 months ago

This right now is impossible as the function gets renamed with the compilation... Maybe we need a flag to compile with keeping the same function names.

karpfediem commented 2 months ago

I think it should be possible to do so per individual function, while keeping the prefix/renaming for everything else.

Mte90 commented 2 months ago

It should make sense to not rename functions and should be fine. Reading the bash generated it is just that, I think that the renaming is used only for the error reporting because includes the line of the original Amber script. Maybe for that is better to use a sourcemap or refer to the original amber script.

It is something that @Ph0enixKM can explain better then me.

Ph0enixKM commented 2 months ago

Function renaming is because we have template functions and the fact that you can declare the same function with the same name in multiple files in Amber. We don't store the position of where in code is the function declared though.

I think that we can easily implement this idea you provided with some env keyword:

env fun foo(name: Text) {
    echo "Hello {name}!"
}
source amber-code.sh
foo "Adam"
# Output: Hello Adam!
b1ek commented 2 months ago

@Ph0enixKM why env? seems very out of place for me

Mte90 commented 2 months ago

Maybe interpreter so in base it is compiled for sh, bash does automatically?