Ph0enixKM / Amber

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

Call Amber function from Bash script #253

Open Mte90 opened 1 week ago

Mte90 commented 1 week 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 1 week ago

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

Mte90 commented 1 week 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 4 days 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 1 day ago

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

Mte90 commented 1 day ago

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