Comments (10)
Will keep the issue Open till I add the fix to the warning/error you mentioned.
from qrgen.
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.
from qrgen.
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)
from qrgen.
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
from qrgen.
Maybe that's because they are not used, so the compiler doesn't expose them.
from qrgen.
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)
from qrgen.
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.
from qrgen.
No problem!
from qrgen.
For anyone else looking at this..
- I updated the build output manually until I can dig deeper into vim and exportjs.
QRT.nim
import
QRgen
block:
let qr = newQR("https://github.com/aruZeta/QRgen")
qr.printTerminal
nim js -d:release "QRT.nim"
QRT.js
//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);
from qrgen.
The mentioned issue about the warning/error with implicit conversion has been fixed in v2.1.1
from qrgen.
Related Issues (20)
- Add more print options HOT 1
- Create a README HOT 1
- Add svg QR code default fill colors
- Rounded alignment patterns in generated SVGs HOT 1
- Separate modules in smaller modules HOT 5
- Move print procedures to DrawedQRCode.nim module
- Better import organization HOT 7
- Fix `GcUnsafe` warnings HOT 1
- Windows "cannot find encoding ISO 8859-1" HOT 14
- Document the code
- Compile to JS HOT 4
- Create images png/jpg HOT 5
- Customize documentation generation HOT 4
- Organize the code better HOT 6
- Write better code HOT 2
- Colab HOT 15
- Use a nix flake instead of shell.nix HOT 1
- Add the ability to render to SVG HOT 4
- Add GitHub action to check if tests pass HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qrgen.