Closed JohnRSim closed 2 years ago
C:\work\tmp\QRgen-main\src\QRgen\private\DrawedQRCode\print.nim(26, 9) Warning: implicit conversion to 'cstring' from a non-const location: if self.drawing[x, y]: "██" else: " "; this will become a compile time error in the future [CStringConv]
That could be fixed easily with
modified src/QRgen/private/DrawedQRCode/print.nim
@@ -15,7 +15,7 @@ proc printTerminal*(self: DrawedQRCode) =
## Print a `DrawedQRCode` to the terminal using `stdout`.
template log(s: string) =
when defined(js):
- console.log s
+ console.log s.cstring
else:
stdout.write s
log "\n\n\n\n\n"
About the generated JS, do you mean the arrays? Those are let {.compileTime.}
variables which are used by QRgen for various tasks, like calculating minimum version, block positions, etc.
Will add the warning/error fix in the next patch release (which will most likely be 2.1.1, since I'm already almost done with 2.1.0)
Thanks for the fast reply! I'm not seeing any exposed functions in the build just those variables.
I'm new to nim - but tried this example https://nim-lang.org/docs/backends.html and it built with js functions and looks good.
Not sure why the js functions aren't being exposed when I do the same with qrgen.nim
Maybe that's because they are not used, so the compiler doesn't expose them.
Take a look at the generated JS with this Nim code:
import
QRgen,
std/[jsconsole]
block:
let qr = newQR("https://github.com/aruZeta/QRgen")
qr.printTerminal
block:
let qr = newQR("https://github.com/aruZeta/QRgen")
console.log((qr.printSvg).cstring)
ah - sorry now I understand. I thought when compiling the JS it auto-exposed newQR
So I could compile as JS and reuse the methods. I'll have a look at std/dom and see if I can expose it to the DOM window.
Thanks aruZeta.
No problem!
Will keep the issue Open till I add the fix to the warning/error you mentioned.
For anyone else looking at this..
import
QRgen
block:
let qr = newQR("https://github.com/aruZeta/QRgen")
qr.printTerminal
nim js -d:release "QRT.nim"
//manually map to generated functions
const getMostEfficientMode = getMostEfficientMode_788529169;
const newQR = newQR_620756998;
const getSmallestVersion = getSmallestVersion_788529195;
const printSvg = printSvg_989855780;
function qrGen(txt,bgHexColor,qrHexColor,alignmentRadius,moduleRadius,moduleSeperation) {
//check string
if ((txt) && (txt.length === 0)) {
console.error('Please supply QR String');
return;
}
//define globals
bgHexColor = bgHexColor || '#ffffff';
qrHexColor = qrHexColor || '#000000';
alignmentRadius = alignmentRadius || 0;
moduleRadius = moduleRadius || 0;
moduleSeperation = moduleSeperation || 0;
//init
const mkstring = makeNimstrLit(txt);
const efficientMode = getMostEfficientMode(mkstring);
const qr = nimCopy(null, newQR(mkstring, 0, efficientMode, getSmallestVersion(mkstring, efficientMode, 0)), NTI687865860);
//return SVG
return toJSStr(printSvg(qr, makeNimstrLit(bgHexColor), makeNimstrLit(qrHexColor), alignmentRadius, moduleRadius, moduleSeperation, makeNimstrLit("qrCode"), [], false));
}
//expose for window/import
window.qrGen = qrGen;
export default qrGen;
import qrGen from './lib/utils/QRT.js';
constmyQR = qrGen('s');
console.log(myQR);
The mentioned issue about the warning/error with implicit conversion has been fixed in v2.1.1
When I run the compiler I get this as the build?
Seeing alot of this with the debug build and no exposed functions.