Re: Exporting json objects to Javascript, how can I make this code more terse?
Compile with `-d:danger` and put name on everything relevant with `{.exportc.}`. Your code will probably go thru a Minifier anyways, so maybe better focus on tests and documentation.
Re: Exporting json objects to Javascript, how can I make this code more terse?
Some more research turned up a macro in jsffi that works the way I want. Here's the improved code. import jsffi type Person = ref object of JsObject name: cstring val: int lang: cstring Rec = ref object of JsObject name: cstring val: int let obj1 {.exportc: "obj1".} = Rec{ friends: [ Person{ val: 19, name: "wendy", lang: "nim" } ], name: "sam", val: 21 } var myobj1 {.exportc: "myobj1".} = obj1 Run
Exporting json objects to Javascript, how can I make this code more terse?
I'm trying to create a json object that is exported and available to other Javascript libraries. Here's a trivial example below. The code below works, I can generate the js file, access the exported vars in the browser js console and it works with my other library. But I wish it weren't so verbose. My real json objects will be much larger, more deeply nested and have many more variations in format. I really like the %* macro in the json module, but the js it generates is not in a format that other libraries can use. How can this be improved? import jsffi # { # "friends": [ # { # "val": 19, # "name": "wendy", # "lang": "nim" # } # ], # "name": "sam", # "val": 21 # } proc makeObj1(): JsObject = result = newJsObject() result.val = 19 result.name = cstring"wendy" result.lang = cstring"nim" proc makeObj2(): JsObject = result = newJsObject() result.friends = [ makeObj1() ] result.name = cstring"sam" result.val = 21 var myobj2 {.exportc: "myobj2".} = makeObj2() Run
Re: RSS feed of nimble.directory doesn't work. Notification is stopping.
Thank you!!
Re: A pure Nim k-d tree
Thanks, I'll look into it.
Javascript browser backend: cannot include more than a single nim compiled source ?
Hi, I am getting strange errors when I include two Nim compiled programs in the same webpage. The scripts are separate, but if I include only one, it works. Including two of them and I'm getting strange errors in the JSON module, or malfunctions that are difficult to reproduce. I'm thinking that maybe the script overwrite each other functions or variables. It's possible since in both scripts, I use the same Nim modules. I'm also thinking that since now JavaScript modules landed in browsers, perhaps Nim could target a javascript module with export directives instead of a script to include inline on a webpage. I'll investigate more, but the error shows on these pages (the first contains both examples and fails somehow): * [https://mildred.github.io/nim-svelte/samples](https://mildred.github.io/nim-svelte/samples)/ * [https://mildred.github.io/nim-svelte/samples/sample1.html](https://mildred.github.io/nim-svelte/samples/sample1.html) * [https://mildred.github.io/nim-svelte/samples/sample2.html](https://mildred.github.io/nim-svelte/samples/sample2.html)
Re: Typography update - now it can render 99% the Google Fonts ttf.
Amazing work! But FYI stacking is very common in Hindu/Sanskrit and Tibetan and other languages for rendering web pages, word processors and so on.
Re: Error: unhandled exception: paramCount is not implemented on Nintendo Switch [OSError]
thanks i will do that
Re: Typography update - now it can render 99% the Google Fonts ttf.
This is amazing and I love it! Good work :)
Re: A pure Nim k-d tree
No, you're right, it allows for it to be adjusted at compile time. I don't think that I've ever seen a k-d tree library that allows for K to be set at runtime. I can't think of a use-case for this. For one, I would think it would come at a large performance hit.
Re: A pure Nim k-d tree
> but that's using a static int, so the K still can not be set at runtime. did > I miss something?
Re: A pure Nim k-d tree
[https://nim-lang.github.io/Nim/manual.html#types-unchecked-arrays](https://nim-lang.github.io/Nim/manual.html#types-unchecked-arrays) Then you could store the length in the tree and not incur the cost of having length + cap, etc. for a using a seq for every point.
Re: A pure Nim k-d tree
There is a genericK branch on the GitHub page. It's fully operational, but I am experiencing challenges with the code. For one, it seems to kill VS Code's ability (nimsuggest, actually, I suspect) to work with the code. And it is significantly slower, which I can't quite understand. I had several tests fail with it as well, which I also don't quite understand. That said, the code compiles and seems to work.
Re: A pure Nim k-d tree
I can't say that I'm familiar with an UncheckedArray. Is there any documentation for it? I can't seem to find any after a quick search.
Re: A pure Nim k-d tree
This looks very promising but K cannot be set at runtime, which limits the use quite a bit. I didn't look at the code too closely, but maybe you could do: type KdPoint*[T:SomeNumber] = UncheckedArray[T] Run
Re: Understanding "Error: cannot evaluate at compile time"
I've been reading all the [issues related to static and templates](https://github.com/nim-lang/Nim/issues?q=is%3Aissue+is%3Aopen+static+template), [macros](https://github.com/nim-lang/Nim/issues?q=is%3Aissue+is%3Aopen+static+macro) and [typedesc](https://github.com/nim-lang/Nim/issues?q=is%3Aissue+is%3Aopen+template+typedesc). I see that I'm entering the fuzzy zone where Nim typing is not totally defined and the syntax is moving. The discussions on generics vs type variables shows that there's no consensus on how types variability must be managed in Nim. And I think that it impacts finding a clean way to solve these types of bugs. Meanwhile, I have to find a way to change my code to stay in Nim safer areas, _if possible_.
Re: RSS feed of nimble.directory doesn't work. Notification is stopping.
Fixed, thank you!
Re: Termcurs
Hello, I'm done. Termcurs it integrates the table (dynamic or static) based on the philosophy of that of the 5250 OS400 there are examples and pictures I will write an application with a real data base provided by Posgresql. We should find the principles of Cobol (for display) or that of RPGILE on OS400, the principles of business management, which are very basic and repetitive to see a real example of usual feasibility in business
Re: Unicode support for Windows 10 console
Back to this subject (and to Nim). To **demotomohiro** : Thanks, **-d:nimDontSetUtf8CodePage** does indeed half the job needed, by creating an executable that does not change Windows console code-page. The other half of the job is to have a piece of software that internally uses UTF-8, so that the same source code works the same in Windows and Linux. In this context **echo** should be overloaded, so that source code using it does not have to be changed, but **io** module functions (like **readLine** ) should be left unchanged, since no function used for file I/O should be tampered with. So I came up with the following solution: #console.nim when system.hostOS == "windows": import encodings import rdstdin import strutils let consoleEncoding = getCurrentEncoding() let consoleEncoder = encodings.open(consoleEncoding, "UTF-8") #stdout let consoleDecoder = encodings.open("UTF-8", consoleEncoding) #stdin template echo(x: varargs[string, `$`]) {.used.} = echo consoleEncoder.convert(x.join("")) template readLineFromStdin(prompt: string): TaintedString {.used.} = consoleDecoder.convert(readLineFromStdin(prompt).string).TaintedString template readLineFromStdin(prompt: string; line: var TaintedString): bool {.used.} = var ts: TaintedString result = readLineFromStdin(prompt, ts) line = consoleDecoder.convert(ts.string).TaintedString proc readLine(): string {.used.} = consoleDecoder.convert(stdin.readLine.string) else: proc readLine(): string {.used.} = stdin.readLine.string Run and import strutils import unicode include console for cp in readLine().utf8: echo cp.toHex, ' ', if cp == "\e": "ESC" else: cp Run **console** has to be **included** , not **imported** , for overloading to work. Now things work on Windows as they should have had from the beginning (that is like on Linux). **Input:** τεστ Run **Output:** CF84 τ CEB5 ε CF83 σ CF84 τ Run I wonder why things are not already done this way in Nim, since the way things are done does not work anyway.
Can the nim compiler run in the browser? Experimenting Nim to template web pages
Hi, Today, I hacked together a simple templating engine in Nim, yet to be perfected. Here it is: [https://mildred.github.io/nim-svelte](https://mildred.github.io/nim-svelte)/ and I was wondering if I could embed the Nim compiler on a webpage to make it possible to play with my code in real-time in the browser. Is it possible? The idea behind my code was to have a templating system that avoided the virtual DOM. I discovered a while ago SvelteJS (at the end of version 2) and it provides a nice alternative to Virtual DOM by updating only DOM nodes that needs updating. It avoids DOM diffing nonsense. With version 3 it also provides JavaScript with reactive abilities for the code logic. It all works by compiling the template file to javascript. Yesterday evening, I took the generated javascript for simple examples and looked it up. I reproduced how it worked in Nim today (with large areas missing still). In addition to that, and to avoid inventing yet another templating syntax, I took the the approach of directly using the HTML `` element and map the elements with a simple DSL in Nim to JSON data structure. That's where I need the Nim compiler on the browser. At first I thought I would need macros or templates, but i nthe end plain procedures with the do syntax worked very well. That's how powerful Nim already is.
Is there a simple example on how to create a Windows UI
Hi, I'm still deciding if I should learn Pascal or Nim. I want to create a Windows GUI app. Using a Pascal tutorial, I could recreate a simple example in less than five minutes. Just a window with a button that, when clicked, shows a "hello world" popup. I know that it will take longer with Nim, but I'd like to get a feeling on how does it works, preferably using one of the most popular libraries at this time. (perhaps [nimx]([https://github.com/yglukhov/nimx](https://github.com/yglukhov/nimx)) or [wNim]([https://khchen.github.io/wNim/)?)](https://khchen.github.io/wNim/\)?\)). Is there a tutorial on how to create a very simple GUI app with Nim? Thanks! On a side note, coming from Python and without a background in programming, I want to create a GUI desktop hotel reservation app. After doing some research on several programming languages, I'm still thinking if I should choose Nim or Pascal.
Re: Typography update - now it can render 99% the Google Fonts ttf.
Kerning already supported ... text would look broken without it. glyph composition and rtl/ttb/btt - I don't support that now, but I want to support it eventually. Hebrew and Arabic are the only major rtl languages I want to support. Almost no one uses ttb/btt in computer UIs, CJK use it in signage and books though. Even traditional Mongolian which is hard ttb is replaced by Cyrillic letters on computers. Doing boustrophedon direction could be fun... but probably just as pointless as Egyptian hieroglyphs pointing their heads in correct orientations.
Re: Typography update - now it can render 99% the Google Fonts ttf.
Rmarkdown looks cool. But I think you might want to use a different tool to generate PDFs... they already support fonts! My plan is to use this for my UI framework called fidget ( [https://github.com/treeform/fidget](https://github.com/treeform/fidget) ). It turns out UI's are like 80% fonts by difficulty.
Re: Typography update - now it can render 99% the Google Fonts ttf.
I use this in my [upcoming game](https://twitter.com/stardust_dev), and I must confirm that it works beautifully (not only on Windows but also on Android!). @treeform is also very responsive to bug reports and fixed the fonts that I found were rendering incorrectly very quickly, thanks @treeform for your amazing work!
Re: Typography update - now it can render 99% the Google Fonts ttf.
Super cool! Do you have plans to support kerning, glyph composition, ltr/rtl/ttb/btt layout fonts? (Or are they already supported?)
Re: Midday Commander [retrofuturistic file manager]
Sure, just finished implementing those stuff myself. **New version is out** , btw: [https://github.com/Guevara-chan/Midday-Commander/releases](https://github.com/Guevara-chan/Midday-Commander/releases) More colors, more folder analysis, more viewer options, more info when doing complex tasks... More everything.
Re: Midday Commander [retrofuturistic file manager]
Honestly it looks cool but I dont have a use for it.
Re: copy & move Access is Denied
In Windows threads can have their own permissions. Did you try a simple program without using wNim?
Re: Typography update - now it can render 99% the Google Fonts ttf.
Something to talk about during Nim conference, right? ;-)
Re: Typography update - now it can render 99% the Google Fonts ttf.
I haven't had a use for this so far, but this is amazing! You have a typo in your URL there. Missing the y at the end. :)