I am working on a C++ extension for a new hardware+editor, but need support. I get it to compile, but it fails with “Cannot read property <> of undefined” in the simulator/browser. I must be doing something wrong with namespaces?!
I used pxt-adafruit as a starting point, but I don’t think it is specific to that. It is not going to be a downloadable extension since it is tied to the hardware. So here are my steps:
setup files like this (content at the bottom, very short files)
pxt-adafruit/libs/x1/pxt.json
pxt-adafruit/libs/x1/x1.cpp
pxt-adafruit/libs/x1/x1.ts
pxt-adafruit/libs/x1/shims.d.ts (autogenerated)
add x1 to pxtarget.json, and libs/circuit-playground/pxt.json
It compiles, the shims.d.ts is successfully auto-generated, but I this simple test fails with "Cannot read property ‘readSomething’ of undefined.
forever(function () {
console.logValue(“x”, x1namespace.readSomething())
})
What is wrong ? Thanks for your support !
pxt-adafruit/libs/x1/x1.cpp:
#include “pxt.h”
namespace x1namespace {
/**
* Reads something
*/
//% blockId=x1readSomething block=“readSomething”
int readSomething() {
return 56;
}
}
pxt-adafruit/libs/x1/x1.ts:
/**
access to x1
*/
//% color=190 weight=100 block=“x1”
namespace x1namespace {
function readSomething(): int32 {
return 57;
}
}
pxt-adafruit/libs/x1/pxt.json:
{
“name”: “x1”,
“description”: “experimental x1”,
“files”: [
“x1.cpp”,
“x1.ts”,
“shims.d.ts”
],
“public”: true,
“dependencies”: {
“core”: “file:…/core”
}
}