Porting SAM to Makecode – part 3

We need to include some C++ and link it to Typescript

A simple example of this

  • Note the /** */. This is required. And it has to be double star (Javadoc style, not /*.
  • Note the //%
  • Note the types. Be careful here
namespace foons {
        /**
         *
         */
        //%
        void fooNative(int x, int y) {
           // your C++ here
        }

}

And the typescript

  • Note the //% shim=
  • Note signature must be the same
  • Cannot use same method name as the C++ – see error below.
/**

 * Define blocks

 */

//%

namespace foons {



    /**

     */

    //% shim=foons::fooNative

    export function foo(x : Number, y : Number): void {

        console.log(x + " " + y)

    }

}

This weird error? This is caused if you inadvertently use the same shim name as the typescript name. You can workaround this by choosing suffix, like fooNative.

main.ts(10,21): error TS2384: Overload signatures must all be ambient or non-ambient.