Amber icon indicating copy to clipboard operation
Amber copied to clipboard

[Feature] Call Amber function from Bash script

Open Mte90 opened this issue 1 year ago • 6 comments

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.

Mte90 avatar Jun 28 '24 08:06 Mte90

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

karpfediem avatar Jun 28 '24 08:06 karpfediem

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.

Mte90 avatar Jun 28 '24 09:06 Mte90

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!

Ph0enixKM avatar Jul 01 '24 12:07 Ph0enixKM

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

b1ek avatar Jul 04 '24 08:07 b1ek

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

Mte90 avatar Jul 04 '24 08:07 Mte90

Using the nameof change suggested in #673, one could write $my_exported_fun() \{ {nameof my_fun} }$ to export a function, which in turn could be made into an stdlib function export() if support for functions as arguments is added.

This would lead to code looking like this:

pub fun my_fun() {
  echo "exported"
}

export(my_fun)

Thesola10 avatar Feb 09 '25 09:02 Thesola10