Giter Site home page Giter Site logo

Comments (10)

aruZeta avatar aruZeta commented on May 30, 2024 1

Will keep the issue Open till I add the fix to the warning/error you mentioned.

from qrgen.

aruZeta avatar aruZeta commented on May 30, 2024
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.

aruZeta avatar aruZeta commented on May 30, 2024

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.

JohnRSim avatar JohnRSim commented on May 30, 2024

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.

aruZeta avatar aruZeta commented on May 30, 2024

Maybe that's because they are not used, so the compiler doesn't expose them.

from qrgen.

aruZeta avatar aruZeta commented on May 30, 2024

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.

JohnRSim avatar JohnRSim commented on May 30, 2024

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.

aruZeta avatar aruZeta commented on May 30, 2024

No problem!

from qrgen.

JohnRSim avatar JohnRSim commented on May 30, 2024

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.

aruZeta avatar aruZeta commented on May 30, 2024

The mentioned issue about the warning/error with implicit conversion has been fixed in v2.1.1

from qrgen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.