Re: [offtopic]2 cross-platform GUI library
on windows. I have tested the following: wNim, which is an alive one among what I have tested and is updated now and then. it supplies many common controls. it can produce tiny size application, but only for windows. I like its autolayout DSL very much, which lets us do the layout in a very brief and effective way. Take only layout into account, wNim's DSL is more effective than XML. fidget. I can't compile the new updated version both wNim and Iup stand on the shoulder of mature cross-platform guide lib. As a result, they should have rich controls and functions. But the soon-abandoned binding is too old and raw, and I have to write application after the C/C++ way, as a result I think the code is verbose and even longer than C/C++ code. what's worse, it is too hard to compile a wxnim, which uses wxWidgets, code on windows. On the contrary, it is easy to compile wxWidgets and its demo on windows. As for LCUI and govcl I mentioned above, I try to call them in python via ctypes since both supply C headers. I can draw the frame and controls on it, but I am stuck during binding the event to controls. I have not try the nim side though. but I think I will be stopped by event binding too.
Re: [offtopic]2 cross-platform GUI library
thank you for pointing out sciter. although it looks nice, I found the document or tutorial is lack, at least for python/nim language.
[offtopic]2 cross-platform GUI library
1\. [https://github.com/lc-soft/LCUI](https://github.com/lc-soft/LCUI) LCUI is a C language UI lib which uses XML and CSS to describe interface structure and style. As a result, the UI can be more beautiful. 2\. [https://github.com/ying32/govcl](https://github.com/ying32/govcl)/ a Golang GUI which is built upon Lazarus' liblcl. So it maybe more mature
ways to comunicate between different application
I am using windows OS. For example, a GUI application is written in nim, in which I choose a lot of excel files to be processed, input the column name in excel files to be read, choose a destination output file name; then these parameters are passed to another application in Python. The Python application will feed back some information to be shown on the nim application's GUI. I can only imagine a way to write the parameters into a text, json or something else file, the the other application reads it. But is there any other ways with pre-built package? Thanks
Re: Recommended GUI library?
the choice depends on your desire heavily. if you just need some button, dialogue box, most of the gui lib maybe work. but if you need grid/cell, web browser and math/latex, only maybe the famous wxdigets/qt, and not so famous iup can work.
Re: Recommended GUI library?
there is a C interface to fltk by D. J. Peters for freebasic language. But since dynamic library is supplied, we can use FLTK-C in other language. As a result, I translate the rich freebasic examples into nim. You can check it at [https://github.com/retsyo/FLTK_nim](https://github.com/retsyo/FLTK_nim) However, I use windows, maybe you have to adjust the code to make it runs on Linux. BTW, is it possible to change the theme in FLTK? The default looking is too nostalgic.
strformat, use a variant as format specifier?
as we all know, both of import strformat var i = 16 echo fmt"{16:x}" echo fmt"{i:x}" Run print 10 now, is it possible to use the format specifier in variant f? None of the following is corrected import strformat var i = 16 f = 'x' Run then echo fmt"{i:f}" Run or echo fmt"{i:{f}}" Run or echo fmt"\{i:{f}\}".fmt Run
how to deal with C string with \0?
As [https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getlogicaldrivestringsw](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getlogicaldrivestringsw) said, the sting in returned lpBuffer is C:\\\0D:\\\0 Run then we can spilt at 0 to tell the real name of logical driver Then I translate the code into nim import winim proc GetLogicalDriveStringsW(nBufferLength: DWORD; lpBuffer: LPTSTR): DWORD {.stdcall, dynlib: "kernel32", importc, discardable.} var szAllDriveStrings = GetLogicalDriveStringsW(0, NULL) echo szAllDriveStrings if szAllDriveStrings > 0: var lpDriveStrings:LPTSTR = cast[LPTSTR](HeapAlloc(GetProcessHeap(), 0, cast[SIZE_T](szAllDriveStrings*sizeof(TCHAR GetLogicalDriveStringsW(szAllDriveStrings, lpDriveStrings) echo lpDriveStrings # only C:\ var x = newString(szAllDriveStrings*sizeof(TCHAR)) copyMem(addr(x[0]), lpDriveStrings, szAllDriveStrings*sizeof(TCHAR)) echo x # C:\D:\ Run so what is the proper way to deal with C's LPTSTR, how can I get C:`, `D:`? No I don't think I sould split the string at `` then attach `` to `C: and D:? to be more common, what if there are more 0 in a C string, how can we deal the information correctly in nim? thanks
question on autolayout in wNim
in my simple code, there is a spacing of 50 between text control and frame border. However if I use H:|[label, groupText]| Run when run the EXE, I get E:\prg\nim\nim-1.0.6\lib\core\macros.nim(581) layout C:\Users\USER\.nimble\pkgs\wnim-0.10.1\wNim\private\wResizer.nim(52) addConstraint C:\Users\USER\.nimble\pkgs\wnim-0.10.1\wNim\private\kiwi\solver.nim(74) addConstraint Error: unhandled exception: [UnsatisfiableConstraintException] Run so how to fix it? thanks import strutils, wNim let app = App() let frame = Frame() let panel = Panel(frame) let label = StaticText(panel, style=wBorderSimple, label=" ".repeat(20)) let text = TextCtrl(panel) let btnClick = Button(panel, label="Click") let btnClose = Button(panel, label="Close") proc layout() = panel.autolayout """ H:|{groupButton:[btnClick(btnClose)]-[btnClose]}| H:{groupText:|-50-[text]|} V:|[label]-[groupText]-[groupButton]| H:|[label, groupText]| """ panel.wEvent_Size do (): layout() layout() frame.center() frame.show() app.mainLoop() Run
2 questions on COM with khchen/winim
Here is a little program which record the text to a wave file. I have tested the similar Python code import winim/com #~ from comtypes.gen import SpeechLib var obj = CreateObject("SAPI.SpVoice") obj.speak "Nim is a statically typed, imperative programming language." var stream = CreateObject("Sapi.SpFileStream") #~ stream.Open "r:/record.wav", SpeechLib.SSFMCreateForWrite, False stream.Open r"r:\record.wav", 3, False var temp_stream = obj.AudioOutputStream obj.AudioOutputStream = stream obj.speak("Hello World") obj.WaitUntilDone(-1) stream.Close() obj.AudioOutputStream = temp_stream Run question 1: what can we do the pyhon code from comtypes.gen import SpeechLib in Nim? I have tried obj.SSFMCreateForWrite, but it is wrong: Error: unhandled exception: unsupported method: SSFMCreateForWrite [COMError] Run question 2: when the above program runs, it fails and says Error: unhandled exception: invoke method failed: AudioOutputStream [COMError] Run so any fix? Thanks
query pc specification?
is there any way or package to query pc specification on Ms Windows is? to be clear, foe example I need to know: CPU type(for example Intel Core i7-8700 @ 3.2Ghz), display card(e.g. Nvidia geforce 1080), 2 hardisk(st31000528as 1T, kbg30xxx Toshiba 256G), memeory(16G), just like what cpu-z does. additional, is it possible to know which monitor/displayer is used? author additional question, is it possible to get all PCs specification under the same LAN? btw, I have searched that Windows Management Instrumentation (Ami maybe useful) but I did not find a smile package for nim yet. thanks
could not load: SDL2_gfx.dll
although it is 3 years ago, I think it is better to write down Now [https://github.com/nim-lang/sdl2/wiki/Windows-Binaries](https://github.com/nim-lang/sdl2/wiki/Windows-Binaries) supplies DLL for windows 32bits however, windows 64bits has been used for many years, so 1\. I can't open the link said in [https://forum.nim-lang.org/t/2730#19404](https://forum.nim-lang.org/t/2730#19404) 2\. ./configure failed to SDL version 2.0.0 by following [https://github.com/Danitegue/pcbasic_brewer/blob/master/HACKING.md](https://github.com/Danitegue/pcbasic_brewer/blob/master/HACKING.md) . Despite I have SDL2 2.0.10 installed. 3\. .vcpkg.exe install sdl2-gfx --triplet x64-windows, mentioned in [https://www.reddit.com/r/rust_gamedev/comments/am84q9/using_sdl2_gfx_on_windows](https://www.reddit.com/r/rust_gamedev/comments/am84q9/using_sdl2_gfx_on_windows)/ by StrangePeopleGames, still failed 4\. finally, I use VC to get the dll as [https://github.com/Danitegue/pcbasic_brewer/blob/master/HACKING.md](https://github.com/Danitegue/pcbasic_brewer/blob/master/HACKING.md) says
https://nim-lang.github.io/Nim/hcr outdated
as the title says, [https://nim-lang.github.io/Nim/hcr](https://nim-lang.github.io/Nim/hcr) is outdated due to the update of sdl2. any plan to update? thanks
Re: wNim - Nim's Windows GUI Framework
offtopic, in the table, there are very long list like "a":a ("wAquamarine": wAquamarine). Is there an concise way to write it?
Re: Nim VS The World (CoffeeScript/Boo/PureBasic/C#/ES2018/Python)
@Libman [http://www.rapideuphoria.com](http://www.rapideuphoria.com)/ [http://hp.vector.co.jp/authors/VA008683/english/index.htm](http://hp.vector.co.jp/authors/VA008683/english/index.htm) [https://www.basic4gl.net/mobile](https://www.basic4gl.net/mobile) [https://www.spiderbasic.com](https://www.spiderbasic.com)/ btw I have written on my Chinese blog to collect many BASIC languages many years ago. Now the blog server deleted many of my posts, but the article can be read on [http://blog.sina.com.cn/s/blog_56b8f7bc010008oc.html](http://blog.sina.com.cn/s/blog_56b8f7bc010008oc.html) and [http://blog.sina.com.cn/s/blog_56b8f7bc010008od.html](http://blog.sina.com.cn/s/blog_56b8f7bc010008od.html) or [http://www.rpgchina.net/forum.php?mod=viewthread=23053](http://www.rpgchina.net/forum.php?mod=viewthread=23053)
Re: What prevents you from using Nim as your main programming language?
vlang.io seems to have a very easy way to use C library which will broaden its ecosystem more easily than other language(including nim) does ok, other parts of vlang are nearly jokes till now
Natural is not positive
here is the code on the [https://nim-lang.org](https://nim-lang.org)/ however, = range 0..9223372036854775807(int) Run how do I know? Just assign a float to age. then nim refuse to compile. so it is a very bad example 1. the comment is wrong. btw, is there any builtin type which is true positive integer or float number? 2. no known man has a age of 9223372036854775807 years old! import strformat type Person = object name: string age: Natural # ensures the age is positive Run
--opt:speed slow down nimpy code
Here is the code from a local discussion group # foo.nim import nimpy proc foo(): seq[array[3,int]]{.exportpy.}= var a:seq[array[3,int]] for i in 1..1000: a.add([i,i*2,0]) return a Run and # a.py import time, foo n=time.time() that=foo.foo() print(time.time()-n) old=time.time() def test(num): a=[] for i in range(num): temp=[i,i*2,0] a.append(temp) return a oh=test(1000) print(time.time()-old) Run when I compile the foo.nim with latest-cloned-and-built nim on Win7 64bits( Nim Compiler Version 0.20.99 [Windows: amd64] Compiled at 2019-06-10) in MSYS2+MINGW with nim c -d:release --threads:on --app:lib --out:foo.pyd foo then R:\>e:\prg\py\Anaconda3_64\python.exe a.py 8.30347490310669 10.290588617324829 R:\>r:\python-2.7.16.amd64\python.exe a.py 13.049248 21.881144 Run shows that nimpy runs faster than pure python which is expected however if I compile the python module with nim c -d:release --threads:on --opt:speed --app:lib --out:foo.pyd foo then R:\>e:\prg\py\Anaconda3_64\python.exe a.py 17.50800108909607 17.381994247436523 R:\>r:\python-2.7.16.amd64\python.exe a.py 17.483676 15.954237 Run it is funny that \--opt:speed slow down the code! What is the problem?
Re: --opt:speed slow down nimpy code
here is the question two: I suspected that set a as a seq in foo.nim is not a good idea for speed( that is true to set a as a list in python version), so what is a better solution?
Re: --opt:speed slow down nimpy code
question three, as we can find that both python 2 and 3 can use the generated pyd files. So the pyd is not a normal python extension which depends on the python version. How does it come? Will this feature slow down the extension? Thanks
Re: Future of Nim ?
library talks. for me, a lot of excel files have to be treated, so I only find and have to rely on python and pandas
Re: wNim fork with ZeeGrid control
can we use it with 64 bits nim?
Re: Nim vs D
why "Projects like Nim and D can never be failures"? what is the common between them? open source? what do you think about redlang [https://www.red-lang.org](https://www.red-lang.org)/ which is said to promote new idea of rebol language, however I think red lang is doomed to fail since it focuses on e-wallet last year.
[some offtopic] 33 = (8866128975287528)^3+(-8778405442862239)^3+(-2736111468807040)^3
Recently, I read that it is the first time that human finds 3 integers x, y and z which make x^3+y^3+z^3=33, where the finding is (8866128975287528)^3+(-8778405442862239)^3+(-2736111468807040)^3 in this March 2019. Till March 2019, we still can't find x, y and z for some numbers, for example, 42, 114, 165, 390, 579 Firstly I think we can make a three-variant-for-loop to find the answer. But obviously it is not a good solution. Maybe GPU can do better than CPU. Then I think some rules may be used: the end number of x^3 can be used to judge. But the if-else maybe takes more time then for-loop So, do you have any idea?
Re: ptr arithmetics?
there is no official/bundle-in function/operator for ptr type, so what is the purpose of ptr type in nimlang?
how to pass a C array to C function?
for example unsigned char imgdata[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...}; Ihandle* image = IupImageRGBA(32, 32, imgdata); Run I tried var imgdata = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0...} var image = iupImageRGBA(32, 32, imgdata) Run but obviuolsy it is wrong. So what is the proper way to make and pass a C array to C function? thanks
tools to wrap C library for both static and dynamic linking?
I have checked c2nim which seems can do most work for using functions in dynamic library without any dynamic linking library file. I also checked wxNim source which seems to be translated by hand for static link, but of cause it can link dynamic library. But is there an aided tool can do most of the work automatically? Thanks
Re: no "--opt:size" leads EXE to "SIGSEGV: Illegal storage access. (Attempt to read from nil?)"
Maybe you have forgotten the binding, but I am using wxnim from [PMunch fork](https://github.com/PMunch/wxnim) from you, [Araq](https://github.com/Araq/wxnim), it is not my wrapping code. And the example2 is in the wxnim too. nim cpp -r -d:useSysAssert -d:useGcAssert example2.nim Run says Traceback (most recent call last) example2.nim(7) example2 example2.nim(40) createFrame SIGSEGV: Illegal storage access. (Attempt to read from nil?) Run where line 07 let f = createFrame() line 40 text.styleSetForeground(wxSTC_STYLE_LINENUMBER, constructWxColour(75, 75, 75) ) line 41 text.styleSetBackground(wxSTC_STYLE_LINENUMBER, constructWxColour(220, 220, 220)) Run if I comment out line 40 and 41, then the compiled EXE can run without crash. I am puzzled why line 7 can passed this time If I change line 40, 41 to line 40 var c1 = cnew constructWxColour(75, 75, 75) line 41 text.styleSetForeground(wxSTC_STYLE_LINENUMBER, c1 ) line 42 var c2 = cnew constructWxColour(220, 220, 220) line 43 text.styleSetBackground(wxSTC_STYLE_LINENUMBER, c2) Run then I get example2.nim(41, 7) Error: type mismatch: got but expected one of: proc styleSetForeground(this: var WxStyledTextCtrl; style: cint; fore: WxColour) first type mismatch at position: 3 required type: WxColour but expression 'c1' is of type: ptr WxColour 1 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them expression: styleSetForeground(text, 33, c1) Run I still don't know how to fix it
no "--opt:size" leads EXE to "SIGSEGV: Illegal storage access. (Attempt to read from nil?)"
I use nim in MSYS2+Mingw64 on Windows 7 64 bits. The involved code can be download [here](https://forums.wxwidgets.org/viewtopic.php?f=27=45513) which uses [wxnim](https://github.com/PMunch/wxnim) . And I have stated the [details to compile wxWidgets](https://github.com/PMunch/wxnim/issues/12) **First of all** I can compile and run the [CPP version by PB](https://forums.wxwidgets.org/viewtopic.php?f=27=45513), no matter with g++ -Os `(/opt/windows_64/bin/wx-config --cflags)` test.cpp `(/opt/windows_64/bin/wx-config --libs all)` Run or g++ `(/opt/windows_64/bin/wx-config --cflags)` test.cpp `(/opt/windows_64/bin/wx-config --libs all)` Run **Then for the nim code** I use $ nim Nim Compiler Version 0.19.9 [Windows: amd64] Compiled at 2019-01-28 Copyright (c) 2006-2018 by Andreas Rumpf Run $ nim cpp -r -d:release --passL:-s --opt:size example2.nim| the EXE runs without crash ---|--- $ nim cpp -r -d:release --passL:-s example2.nim| the EXE runs and crash $ nim cpp -r -d:release --opt:size example2.nim| the EXE runs without crash $ nim cpp -r -d:release example2.nim| the EXE runs and crash all the crashes says SIGSEGV: Illegal storage access. (Attempt to read from nil?) Error: execution of an external program failed: 'C:\Users\USER\.nimble\pkgs\wxnim-0.8.0\examples\purewx\example2.exe ' Run of cause, all the EXE files have different file size. so what is the problem and how to fix it? Thanks
Re: Internationalization of unmodified source code at compile time i18n
nice, suggest to use getAppDir in os to let nimterlingua load the trasnlation file from the app path defaultly
how to use PassC/PassL pragma?
on my machine( MSYS2 + MingW64, windows 64bits) $ wx-config --libs -LE:/msys64/mingw64/lib -pipe -Wl,--subsystem,windows -mwindows -lwx_mswu_xrc-3.0 -lwx_mswu_webview-3.0 -lwx_mswu_html-3.0 -lwx_mswu_qa-3.0 -lwx_mswu_adv-3.0 -lwx_mswu_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0 $ wx-config --cppflags -IE:/msys64/mingw64/lib/wx/include/msw-unicode-3.0 -IE:/msys64/mingw64/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__ Run In wxCompile.nim of [wxnim](https://github.com/PMunch/wxnim), the code const wxConfig = "wx-config" {.passC: "`" & wxConfig & " --cppflags`".} {.passL: "`" & wxConfig & " --libs`".} Run will not be compiled because the back quote mark: $ nim cpp -r controlgallery.nim ... Error: execution of an external compiler program 'g++.exe -c -w -mno-ms-bitfields -w -fpermissive -mno-ms-bitfields -DWIN32_LEAN_AND_MEAN `wx-config --cppflags` -IE:\msys64\home\USER\_nim\nim\lib -IR:\examples\genuimacro -o C:\Users\USER\nimcache\controlgallery_d\stdlib_helpers2.cpp.o C:\Users\USER\nimcache\controlgallery_d\stdlib_helpers2.cpp' failed with exit code: 1 g++.exe: error: `wx-config: No such file or directory g++.exe: error: unrecognized command line option '--cppflags`' Run Although it is not right but we can find the passC and passL actually pass the string to compiler After reading [doc](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-passc-pragma), I change the code in wxCompile.nim of [wxnim](https://github.com/PMunch/wxnim) to const wxConfig = "wx-config" {.passC: gorge(wxConfig & " --cppflags").} {.passL: gorge(wxConfig & " --libs all").} Run but $ nim cpp -r controlgallery.nim ... Error: execution of an external compiler program 'g++.exe -c -w -mno-ms-bitfields -w -fpermissive -mno-ms-bitfields -DWIN32_LEAN_AND_MEAN -IE:\msys64\home\USER\_nim\nim\lib -IR:\examples\genuimacro -o C:\Users\USER\nimcache\controlgallery_d\wxnim_wx.cpp.o C:\Users\USER\nimcache\controlgallery_d\wxnim_wx.cpp' failed with exit code: 1 C:\Users\USER\nimcache\controlgallery_d\wxnim_wx.cpp:10:23: fatal error: wx/wxprec.h: No such file or directory #include ^ compilation terminated. Run as you can find, passC and passL are not passed to g++ So why and what is the proper code here? Thanks
Re: is it possible to write a converter which only convert 0 to nil
hi, Stefan_Salewski You find the lazy bone in me exactly, thank you for the explaination. Now the original Code( in [FreeBASIC](https://www.freebasic.net/) ) #include once "fltk-c. bi" sub QuitCB cdecl (byval self as Fl_Widget ptr,byval userdata as any ptr) flMessageTitle("QuitCB called !") if flChoice("Do you really want to exit ?","no","yes") then Fl_WindowHide Fl_WidgetWindow(self) end if end sub ' ' main ' var win = Fl_WindowNew(640,480) var bar = Fl_Menu_BarNew(0,0,Fl_WidgetGetW(win),25) ' Fl_ALIGN_TEXT_OVER_IMAGE Fl_WindowShow win ' <- must be shown for drawing ' params: menu, mnuPath ,mnuLabel , image ,[shortcut],[@MenuCB],IMAGE_ALIGN , LABEL_ALIGN Fl_Menu_AddImageLabel(bar,"File/Test1","Test" ,"media/8x8. png", , ,Fl_ALIGN_IMAGE_OVER_TEXT, Fl_ALIGN_LEFT) Fl_Menu_AddImageLabel(bar,"File/Test2","Test" ,"media/8x8. png", , ,Fl_ALIGN_TEXT_OVER_IMAGE, Fl_ALIGN_RIGHT) Fl_Menu_AddImageLabel(bar,"File/Open1","Open. . . ","media/16x16. png", , ,Fl_ALIGN_IMAGE_NEXT_TO_TEXT, Fl_ALIGN_LEFT or FL_ALIGN_TOP) Fl_Menu_AddImageLabel(bar,"File/Open2","Open. . . ","media/16x16. png", , ,Fl_ALIGN_IMAGE_NEXT_TO_TEXT, Fl_ALIGN_CENTER) Fl_Menu_AddImageLabel(bar,"File/Open3","Open. . . ","media/16x16. png", , ,Fl_ALIGN_IMAGE_NEXT_TO_TEXT, Fl_ALIGN_RIGHT or FL_ALIGN_BOTTOM) Fl_Menu_AddImageLabel(bar,"File/Exit3","Exit" ,"media/exit-2_32x32. png" ,,@QuitCB,Fl_ALIGN_TEXT_NEXT_TO_IMAGE, Fl_ALIGN_RIGHT or FL_ALIGN_BOTTOM) Fl_Menu_AddImageLabel(bar,"File/Exit2","Exit" ,"media/application-exit-4_32x32. png",,@QuitCB,Fl_ALIGN_TEXT_NEXT_TO_IMAGE, Fl_ALIGN_CENTER) Fl_Menu_AddImageLabel(bar,"File/Exit1","Exit" ,"media/exit-2_32x32. png" ,,@QuitCB,Fl_ALIGN_TEXT_NEXT_TO_IMAGE, Fl_ALIGN_LEFT or FL_ALIGN_TOP) Fl_Run Run can be written with [my nim binding](https://forum.nim-lang.org/t/4561) as import fltk_main import fltk_tools proc QuitCB (self: ptr Fl_Widget, userdata: pointer) {.cdecl.} = flMessageTitle("QuitCB called !") if flChoice("Do you really want to exit ?","no","yes") > 0 : Fl_WindowHide Fl_WidgetWindow(self) var win = Fl_WindowNew(640,480) var bar = Fl_Menu_BarNew(0,0,Fl_WidgetGetW(win),25) #' Fl_ALIGN_TEXT_OVER_IMAGE Fl_WindowShow win #' <- must be shown for drawing #~ ' params:menu, mnuPath,mnuLabel, image,[shortcut],[MenuCB],IMAGE_ALIGN, LABEL_ALIGN # you can use 0 or nil for the dummy MenuCB Fl_Menu_AddImageLabel(bar, "File/Test1", "Test", "media/8x8.png", 0, 0, Fl_ALIGN_IMAGE_OVER_TEXT, Fl_ALIGN_LEFT) Fl_Menu_AddImageLabel(bar, "File/Test2", "Test", "media/8x8.png", 0, nil, Fl_ALIGN_TEXT_OVER_IMAGE, Fl_ALIGN_RIGHT) Fl_Menu_AddImageLabel(bar, "File/Open1", "Open...", "media/16x16.png", 0, 0, Fl_ALIGN_IMAGE_NEXT_TO_TEXT, Fl_ALIGN_LEFT or FL_ALIGN_TOP) Fl_Menu_AddImageLabel(bar, "File/Open2", "Open...", "media/16x16.png", 0, 0, Fl_ALIGN_IMAGE_NEXT_TO_TEXT, Fl_ALIGN_CENTER) Fl_Menu_AddImageLabel(bar, "File/Open3", "Open...", "media/16x16.png", 0, 0, Fl_ALIGN_IMAGE_NEXT_TO_TEXT, Fl_ALIGN_RIGHT or FL_ALIGN_BOTTOM) Fl_Menu_AddImageLabel(bar, "File/Exit3", "Exit", "media/exit-2_32x32.png", 0, QuitCB, Fl_ALIGN_TEXT_NEXT_TO_IMAGE, Fl_ALIGN_RIGHT or FL_ALIGN_BOTTOM) Fl_Menu_AddImageLabel(bar, "File/Exit2", "Exit", "media/application-exit-4_32x32.png", 0, QuitCB, Fl_ALIGN_TEXT_NEXT_TO_IMAGE, Fl_ALIGN_CENTER) Fl_Menu_AddImageLabel(bar, "File/Exit1", "Exit", "media/exit-2_32x32.png", 0, QuitCB, Fl_ALIGN_TEXT_NEXT_TO_IMAGE, Fl_ALIGN_LEFT or FL_ALIGN_TOP) Fl_Run() Run
Re: [release]binding for FLTK C dynamic library
The style is the last thing to consider. The first thing is to make a full and corrected binding with all examples written in nim without any problem, so I have to keep the original lower/upper case in code in order to refer to the original header files( there are both C and FreeBasic) and examples( there is only FreeBasic code for the FLTK **C** ). FreeBasic ignores the lower/upper case.
Re: [release]binding for FLTK C dynamic library
updated. now most of the problem codes are: 1. OpenGl related 2. FreeBasic macro, or in other word, C's #define related. So that almost no function has EX in the name can run 3. Fl_Shared_ImageImages related
is it possible to write a converter which only convert 0 to nil
The C code int setCallback(Fl_Widget* wgt, Fl_Callback *cb, void *pdata=NULL, int num=1); Run can be translated into proc setCallback*(wgt: ptr Fl_Widget; cb: ptr Fl_Callback; pdata: pointer = nil; num: cint = 1): cint Run Instead of setCallback(wgt, cb, nil, 2) Run I want to call the function as setCallback(wgt, cb, 0, 2) Run I have tried use converter toNil(x: int=0): type(nil) = nil Run but Error: invalid type: 'nil' in this context: 'proc (x: int): nil' for proc Run so, is it possible to write a convertor which actually convert number zero only to nil? thanks
Re: questions on binding C DLL
guys, I think it is far beyond my ability to create my own widget
Re: questions on binding C DLL
1. Yes, [FLTK]([http://www.fltk.org](http://www.fltk.org)) uses C++, but [D.J.Peters's FLTK **C** for FreeBasic]([https://www.freebasic.net/forum/viewtopic.php?f=14=24547=180](https://www.freebasic.net/forum/viewtopic.php?f=14=24547=180)) supplies a C interface() just like the old wx-c did), which is my [project]([https://forum.nim-lang.org/t/4561](https://forum.nim-lang.org/t/4561)) and [question ]([https://forum.nim-lang.org/t/4569](https://forum.nim-lang.org/t/4569)) based on. 2. the line void Fl_Widget_TrackerDelete(Fl_Widget_Tracker* & wt); is actually void DLL_EXPORT Fl_Widget_TrackerDelete(Fl_Widget_Tracker* & wt); on line 119 in fltk-c-1.3.3-srcfltk-c-wrapper-widget.h however to be frankly I can compile [FLTK]([http://www.fltk.org)](http://www.fltk.org\)), but don't know how to compile [D.J.Peters's FLTK **C** for FreeBasic]([https://www.freebasic.net/forum/viewtopic.php?f=14=24547=180](https://www.freebasic.net/forum/viewtopic.php?f=14=24547=180)) from source in Msys2+Mingw64 on Windows 7 1. Currently, table(not tab)/cells widget can just meet my need to represent the data, but eventually I hope there will be a Microsoft EXCEL-like widget instead so that the user can use mouse to sort the cells by column value(s). 2. A glimpse of ui/nimx offical image says "no, there is no table widget". 3. In fact, I prefer to [wxnim]([https://github.com/PMunch/wxnim](https://github.com/PMunch/wxnim)) since I have some experience in using [wxPython]([https://wxpython.org/](https://wxpython.org/)) before. However I can't figure out how to [compile it in Msys2+Mingw64 on Windows 7]([https://github.com/PMunch/wxnim/issues/12](https://github.com/PMunch/wxnim/issues/12)) 4. I have also checked the mentioned [nfltk]([https://github.com/Skrylar/nfltk)](https://github.com/Skrylar/nfltk\)), but I can't figure out how to [compile it in Msys2+Mingw64 on Windows 7]([https://github.com/Skrylar/nfltk/issues/2](https://github.com/Skrylar/nfltk/issues/2)) 5. "why not hiring someone work for you". Sorry, I have never thought about it since I think I can't afford it. So I try to do it by myself while studying nimlang with the help of forum/document/google All the above 1, 3, 4, 5, 6 have been mentioned in fact.
Re: Using Stack Overflow for help
I think most of the post you mentioned will be closed by stack overflow moderator very soon
Re: questions on binding C DLL
Thanks I don't mean to throw tons of code line, so I extract some typical ( at least I think) function declaration lines, even in C header files they looks the same. The other lines, which I did not enclose here, can be treated by c2nim or my newbie's brain. As for the C header files, actually I already mentioned them in ([release]binding for FLTK C dynamic library)[[https://forum.nim-lang.org/t/4561](https://forum.nim-lang.org/t/4561)]
Re: yet another question on code substitution with templates
the code is not too long for me to replace all DOP_COLOR(sth) with HIWORD(sth), LOWORD(sth) by hand. But it is some long for concat thus the code will be a mess. But to speak generaly, there is no something like #define A B directive in C, which only replace A with B literally, in nim, isn't? Yes, I know #define must be used carefully even in C, but I am seeking an elegant workaround in nim. #define DOP_COLOR(col) HIWORD(col), LOWORD(col) dim as short opcodes(...)=> { _ FL_DOP_COLOR ,DOP_COLOR(FL_RED), _ FL_DOP_LINE, _ FL_DOP_VERTEX,0,0, _ FL_DOP_VERTEX,1,1, _ FL_DOP_END , _ FL_DOP_COLOR ,DOP_COLOR(FL_GREEN), _ FL_DOP_LINE, _ FL_DOP_VERTEX,0,1, _ FL_DOP_VERTEX,1,0, _ FL_DOP_END , _ FL_DOP_COLOR ,DOP_COLOR(FL_BLUE), _ FL_DOP_LINE, _ FL_DOP_VERTEX,0, 5000, _ FL_DOP_VERTEX,1, 5000, _ FL_DOP_END , _ FL_DOP_COLOR ,DOP_COLOR(Fl_DARK_YELLOW), _ FL_DOP_POLYGON , _ FL_DOP_VERTEX, 1000, 1000, _ FL_DOP_VERTEX, 1000, 9000, _ FL_DOP_VERTEX, 9000, 9000, _ FL_DOP_VERTEX, 9000, 1000, _ FL_DOP_VERTEX, 1000, 1000, _ _ ' opposite direction = hole FL_DOP_VERTEX, 1500, 1500, _ FL_DOP_VERTEX, 8500, 1500, _ FL_DOP_VERTEX, 8500, 8500, _ FL_DOP_VERTEX, 1500, 8500, _ FL_DOP_VERTEX, 1500, 1500, _ FL_DOP_END _ } Run
questions on binding C DLL
first, some questions about pointer **question 1** void Fl_Widget_TrackerDelete(Fl_Widget_Tracker* & wt); Run c2nim says Error: token expected: ) **question 2** void flFileChooserCallback(void(*cb)(const char* f)); Run c2nim says proc flFileChooserCallback*(cb: proc (f: cstring)) Run but where the * before cb has gone? **question 3** how to judge a pointer points to NULL? currently I use if ans == cast[pointer](0): Run but I am not sure whether is this safe or not. And I don't really like to write this long code every time. In FreeBasic, it can be written as if ans = 0 then ' in BASIC, one `=` can be used to comparison too Run **question 4** in many FreeBasic code, any ptr can be used like sub TreeCB cdecl (byval wgt as Fl_Widget ptr,byval tree as any ptr) ' this is the callback function dim as Fl_Tree_Item ptr item = Fl_TreeGetCallbackItem(tree) do something end sub Run then var tree = Fl_TreeNew(10,20,300,170,"Fl_Tree") Fl_WidgetSetCallbackArg(tree,@TreeCB,tree) ' setup a callback for the treeview Run What I do in nim: proc TreeCB (self: ptr Fl_Widget, tree: ptr Fl_Tree){.cdecl.} = var item = Fl_TreeGetCallbackItem(tree) do something var tree = Fl_TreeNew(10, 20, 300, 170, "Fl_Tree") Fl_WidgetSetCallbackArg(tree, TreeCB, tree) # setup a callback for the treeview Run you may find that I have to use tree: ptr Fl_Tree while declaration the callback function explicitly else I have to write var item = Fl_TreeGetCallbackItem(cast[ptr Fl_Tree](tree)) Run thanks
Re: yet another question on code substitution with templates
sorry, I can't still grasp the idea if emit is used, then how to use DOP_COLOR in nim code obviously, {. emit: """ #define DOP_COLOR(col) HIWORD(col), LOWORD(col) """ .} var opcodes = [ FL_DOP_COLOR ,DOP_COLOR(FL_RED), FL_DOP_LINE, ] Run says undeclared identifier: 'DOP_COLOR' Run the tuple solution template DOP_COLOR(col: untyped):untyped= (HIWORD(col), LOWORD(col)) var opcodes = [ FL_DOP_COLOR ,DOP_COLOR(FL_RED), FL_DOP_LINE, ] Run says Error: type mismatch: got but expected 'FL_DATAOPCODE = enum' Run
yet another question on code substitution with templates
I have read [https://forum.nim-lang.org/t/3199](https://forum.nim-lang.org/t/3199) but I am still puzzled my situation is, I need the #define part works like that in C/FreeBasic, so if #define DOP_COLOR(col) HIWORD(col), LOWORD(col) Run then the code to create array in FreeBasic dim as short opcodes(...)=> { _ FL_DOP_COLOR ,DOP_COLOR(FL_RED), _ FL_DOP_LINE, _ } Run is expanded to dim as short opcodes(...)=> { _ FL_DOP_COLOR ,HIWORD(FL_RED), LOWORD(FL_RED), _ FL_DOP_LINE, _ } Run My try is actually failed template DOP_COLOR(col: untyped):untyped= HIWORD(col), LOWORD(col) Run Error: invalid indentation Run thanks
the ignoring of _ make some translation need more work
for example, in FLTK C for FreeBasic, there is (faked) enum FL_TEXT_DISPLAY_WRAP_MODE, i.e. type FL_TEXT_DISPLAY_WRAP_MODE as ulong Run which is used in funtions like declare sub Fl_Text_DisplayWrapMode(byval td as Fl_Text_Display ptr, byval wrap as FL_TEXT_DISPLAY_WRAP_MODE, byval wrap_margin as long) Run As we can read, the type name FL_TEXT_DISPLAY_WRAP_MODE is same as the function name Fl_Text_DisplayWrapMode in nim! So an extra effort has been spend on it Can we make nim 1. case sensitive 2. _ sensitive ?
[release]binding for FLTK C dynamic library
[https://github.com/retsyo/FLTK_nim](https://github.com/retsyo/FLTK_nim)/ As all my released projects, it needs more works to finish. I do hope someone, who knows nimlang well, can join or give suggestions import fltk_main proc ButtonClick (button: ptr FL_WIDGET, arg: pointer):cint {.cdecl.} = Fl_WidgetCopyLabel(button, "do it again") var Win = Fl_WindowNew(320, 200, "What a shiny Window :-)") var Btn = Fl_ButtonNew(10, 10, 120, 32, "click me") Fl_WidgetSetCallback(Btn, ButtonClick) Fl_WindowShow(Win) Fl_Run() Run p.s. In case someone asks, # why not to use 1. [FreeBasic[(http://freebasic.net/)? because I need to handle many text in my work, but I hate to write such in any BASIC 2. [nfltk](https://github.com/Skrylar/nfltk). because I can't compile it in my MSYS2+MingW64 on Windows 7 3. wxWidgets? because I can't compile it in my MSYS2+MingW32 on Windows 7 3. QT? because I don't know how to compile it in my MSYS2+MingW64/32 on Windows 7 4. [ui](https://github.com/nim-lang/ui)? because I needs widgets to write spreedsheet app 5. web engine and HTML/js? I don't know how to do that. But I do find http://tabulator.info is pretty 6. Python + QT/wxWidgets? Yes I do use them. But I find that some app built with py2exe/pyinstaller does not run on any Windows version. 7. 2 space for indentation? Well, this project is opensourced, please give you effort to it # why the EXE file is big? I don't know # how to do static link? I don't know how to do that in nimlang and FreeBasic. Do we need to supply another binding? BTW, `static link` is allowed by FLTK, and you do not need to opensource your code. # why do you always test/bind blaah blaah libraries In fact, I don't mean to do that but I can't find a ready-to-use binding. # License I choose [FLTK's lincense](https://www.fltk.org/COPYING.php). But a note in your appliaction such as "FLTK_nim is used" is appreciated. Run
template/macro to create function/variant?
In freebasic, for code #macro DeclareEx(_name_) declare function _name_##ExNew(byval x as long, byval y as long, byval w as long, byval h as long, byval title as const zstring ptr=0) as _name_##Ex ptr declare sub _name_##ExDelete (byref ex as _name_##Ex ptr) #endmacro Run if we call DeclareEx(Fl_Button) then we get the 2 procedure declare function Fl_ButtonExNew(byval x as long, byval y as long, byval w as long, byval h as long, byval title as const zstring ptr=0) as Fl_Button ptr declare sub Fl_ButtonExDelete (byref ex as Fl_ButtonEx ptr) Run how can we do that in nim? I have tried template and macro. template Kitten*(name: string) = var name_1 = "Mike" Kitten("q") echo q_1 Run says a.nim(6, 6) Error: undeclared identifier: 'q_1' Run at same time macro Kitten*(name: string) : untyped = var name_1 = "Mike" Kitten("q") echo q_1 Run says a.nim(2, 7) Hint: 'name_1' is declared but not used [XDeclaredButNotUsed] a.nim(6, 6) Error: undeclared identifier: 'q_1' Run thnaks
template/macro to create function/variant
In freebasic, for code #macro DeclareEx(_name_) declare function _name_##ExNew(byval x as long, byval y as long, byval w as long, byval h as long, byval title as const zstring ptr=0) as _name_##Ex ptr declare sub _name_##ExDelete (byref ex as _name_##Ex ptr) #endmacro Run if we call DeclareEx(Fl_Button) then we get the 2 procedure declare function Fl_ButtonExNew(byval x as long, byval y as long, byval w as long, byval h as long, byval title as const zstring ptr=0) as Fl_Button ptr declare sub Fl_ButtonExDelete (byref ex as Fl_ButtonEx ptr) Run how can we do that in nim? I have tried template and macro. template Kitten*(name: string) = var name_1 = "Mike" Kitten("q") echo q_1 Run says a.nim(6, 6) Error: undeclared identifier: 'q_1' Run at same time macro Kitten*(name: string) : untyped = var name_1 = "Mike" Kitten("q") echo q_1 Run says a.nim(2, 7) Hint: 'name_1' is declared but not used [XDeclaredButNotUsed] a.nim(6, 6) Error: undeclared identifier: 'q_1' Run thnaks
Re: still no success binding DLL's callback function
Let me ignore the data type first ;) I hope there is a VisualBasic-Freebasic-C-Nim data type comparasion sheet type Fl_Callback* = proc(widget: ptr Fl_Widget, pData: ptr any):cint {.cdecl.} proc ButtonClick (button: ptr FL_WIDGET, arg: ptr any):cint {.cdecl.} = Fl_WidgetCopyLabel(button, "do it again") Fl_WidgetSetCallback(Btn, ButtonClick) Run says a.nim(45, 27) template/generic instantiation of `ButtonClick` from here a.nim(40, 42) Error: cannot instantiate: 'arg:type' Run
Re: Introducing the nimgen family of Nim wrappers
on windows, nimgen will run something like cmd /c "c2nim ..." Run but I am using MSYS2+Mingw, thus "cmd /c" will make the command invalid. Is there a solution?
still no success binding DLL's callback function
I have posted days ago [https://forum.nim-lang.org/t/4522](https://forum.nim-lang.org/t/4522) in which I try to bind xcgui which is a free 32bits dll for windows Now I try to bind FLTK([http://www.fltk.org)](http://www.fltk.org\)). I can compile FLTK, test, examples and fluid with my MSYS2+MingW64 on Win7 64 bits I know there is already [https://github.com/Skrylar/nfltk](https://github.com/Skrylar/nfltk), but so bad, the test.nim can not be compiled, my msys2 halted for hours on lines Hint: nimwidget [Processing] CC: fltk_test CC: fltk_enumerations Run However I am not trying to translated the official FLTK C header by myself again. C's pointer are always beats me, and I found a nice FLTK binding( and tons of examples) for freebasic by D.J.Peters on [https://www.freebasic.net/forum/viewtopic.php?f=14=24547](https://www.freebasic.net/forum/viewtopic.php?f=14=24547) In the work of D.J.Peters, there are prebuilt fltk-c-1.3.3-32.dll fltk-c-1.3.3-64.dll libfltk-c-1.3.3-32-arm.so libfltk-c-1.3.3-32-syslib.so libfltk-c-1.3.3-32.so libfltk-c-1.3.3-64-syslib.so libfltk-c-1.3.3-64.so Run so I just mimicked and got the following code import winim # for the L"" type long = int16 Fl_Widget = int16 Fl_Window = int16 Fl_Button = int16 #~ Fl_Callback = int16 const fltk* = "fltk-c-1.3.3-64.dll" type Ihandle = object PIhandle* = ptr Ihandle Icallback* = proc (arg: PIhandle): cint {.cdecl.} Fl_Callback* = proc(widget: ptr Fl_Widget, pData: ptr any) proc Fl_WindowNew(byval: long, h: long, title:cstring): ptr Fl_Window{. cdecl, importc: "Fl_WindowNew", dynlib: fltk, discardable.} proc Fl_ButtonNew(x: long, y: long, w: long, h: long, label: cstring) : ptr Fl_Button{. cdecl, importc: "Fl_ButtonNew", dynlib: fltk, discardable.} proc Fl_WidgetSetCallback(wgt: ptr Fl_Widget, cb:Fl_Callback){. cdecl, importc: "Fl_WidgetSetCallback", dynlib: fltk, discardable.} proc Fl_WindowShow(win: ptr Fl_Window){. cdecl, importc: "Fl_WindowShow", dynlib: fltk, discardable.} proc Fl_Run(): long{. cdecl, importc: "Fl_Run", dynlib: fltk, discardable.} proc Fl_WidgetCopyLabel(wgt: ptr Fl_Widget; caption: ptr WCHAR){. cdecl, importc: "Fl_WidgetCopyLabel", dynlib: fltk, discardable.} proc ButtonClick (button: ptr FL_WIDGET, arg: ptr any):cint {.cdecl.} = Fl_WidgetCopyLabel(button, "do it again") var Win = Fl_WindowNew(320, 200, "What a shiny Window :-)") var Btn = Fl_ButtonNew(10, 10, 120, 32, "click me") #~ Fl_WidgetSetCallback(Btn, ButtonClick) #~ Fl_WidgetSetCallback(cast[ptr Fl_Widget](Btn), (ButtonClick)) #~ Fl_WidgetSetCallback(cast[ptr Fl_Widget](Btn), cast[Fl_Callback](ButtonClick)) Fl_WindowShow(Win) Fl_Run() Run this code can run without the Fl_WidgetSetCallback line. If I use Fl_WidgetSetCallback(Btn, ButtonClick) Run I get a.nim(45, 21) Error: type mismatch: got but expected one of: proc Fl_WidgetSetCallback(wgt: ptr Fl_Widget; cb: Fl_Callback) first type mismatch at position: 2 required type: Fl_Callback but expression 'ButtonClick' is of type: proc (button: ptr Fl_Widget, arg: ptr GenericParam): cint{.cdecl.} expression: Fl_WidgetSetCallback(Btn, ButtonClick) Run elif I use Fl_WidgetSetCallback(cast[ptr Fl_Widget](Btn), (ButtonClick)) Run I get a.nim(46, 21) Error: type mismatch: got but expected one of: proc Fl_WidgetSetCallback(wgt: ptr Fl_Widget; cb: Fl_Callback) first type mismatch at position: 2 required type: Fl_Callback but expression 'ButtonClick' is of type: proc (button: ptr Fl_Widget, arg: ptr GenericParam): cint{.cdecl.} expression: Fl_WidgetSetCallback(cast[ptr Fl_Widget](Btn), ButtonClick) Run elif I use Fl_WidgetSetCallback(cast[ptr Fl_Widget](Btn), cast[Fl_Callback](ButtonClick)) Run I get a.nim(47, 53) Error: cannot cast to a non concrete type: 'Fl_Callback' Run Please, can anyone give clear help? Thanks
Re: trouble during wrapping a windows DLL
do you mean proc OnClick*(bHandle: var bool): cint {.exportc, cdecl.} = setupForeignThreadGc() var sel = XC_MessageBox(nil, "炫彩界面库pText", "pCaption", 1) bHandle = true result = 0 tearDownForeignThreadGc() Run it still crashes after the msgbox appears btw, I have add ` --threads:on --tlsEmulation:off` to compile the source
Re: it is hard to load forum.nim-lang.org for months
I have tried to go here with and without Lantern.
Re: trouble during wrapping a windows DLL
I don't know Go-lang, and I don't have time to learn it. As I always state, I _do not_ make a living on programing, I only program in my spare time, sometimes I make some app to help me or co-worker in job. That is why I use Python mainly because Python is simple and has tons of libraries which almost meets what I need. But since some bundled exe file from python source file via pyinstaller/py2exe failed to run on every PCs, I try to use nim to make app with little or no extra dependencies, the other reason why I choose nim is because nim looks like python. But it seems this is a tough choice. So if possible, please make some help to improve nim's weak ecological environment. I don't have too much time and experience in programing As for the document, the binding use XCGUI function directly, if you need you should read XCGUI's manual which is supplied by www.xcgui.com
Re: trouble during wrapping a windows DLL
I have found that no mmatter the is cast[cstring] or not, the compiled app still crash after I click the button and the msgbox shows here is the line in C header XC_API BOOL WINAPI XEle_RegEventC(HELE hEle, int nEvent, void *pFun); Run here is what VB code does Public Function OnClick(ByRef bHandle As Long) As Long MsgBox "炫彩界面库" bHandle = True OnClick = 0 End Function Private Sub Main() XEle_RegEventC hBtn, XE_BNCLICK, AddressOf OnClick End Sub Run
trouble during wrapping a windows DLL
I am trying to write a binding for www.xcgui.com which is a GUI lib for windows. The initial code is on [https://github.com/retsyo/xcgui_nim](https://github.com/retsyo/xcgui_nim) but I met some questions. for example import ../../xcgui import winim/inc/[windef, wingdi] import winim/winstr import sugar proc OnClick(bHandle: var bool): cint = var sel = XC_MessageBox(nil, "炫彩界面库pText", "pCaption", 1) bHandle = true return 0 proc Main() = #~ type ptrFnCallBack = (proc(bHandle: var bool): cint) #~ type ptrFnCallBack = (cint - > cint)# sugar does not work #~ var fnCallBack: ptrFnCallBack = OnClick var bOk = XInitXCGUI() if bOk == True: var hWindow = XWnd_Create(0, 0, 300, 200, "炫彩NIM例子", 0, xc_window_style_default) if hWindow != nil : var hBtn = XBtn_Create(8, 30, 100, 20, "点我", hWindow) if hBtn != nil : XEle_RegEventC( hBtn, XE_BNCLICK, cast[cstring](OnClick)) XWnd_ShowWindow(hWindow, 5) XRunXCGUI() else: echo "a" XExitXCGUI() if isMainModule: Main() Run will crash if I click the button SIGSEGV: Illegal storage access. (Attempt to read from nil?) Error: execution of an external program failed: 'E:\my_project\nim\xcgui_\nim_\Cpp\002buttonevent\WinMain.exe ' Run can someone help me to fix it? thanks
it is hard to load forum.nim-lang.org for months
I have tried IE, Firefox and Chrome on my Win7 64bits with and without proxy, but in these months it is very hard for me to load [https://forum.nim-lang.org](https://forum.nim-lang.org)/ or any posts url. No error is displayed, all these web browsers just finished with a blank page but the title can be read from the tab. I have to reload the pages several times, sometime the forum can be shown after many reloads, but sometime I just can't load the web page whole day. So how can I fix it? Thanks
Porting MSWin to Linux
sorry to reply in this old posts. but I am still (I almost have spent one year) looking for GUI solution(s) which have already exposed many widgets/controls for windows OS. So I really want to know 1\. which is the latest sciter binding for nim? Google finds https://github.com/oskca/nsciter which is released in 2016 and there is only one demo. Is there anymore demos? 2\. @OderWat, has METATEXX GmbH released your wxWidget bindings? Thanks
seek for help on porting VB lib to nim
in the VB lib, which calls functions in 32bits DLL, there are something I am not very sure 1\. many arguments are declared as LONG in the VB files. I found that LONG is signed 64-bit integers on [https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/data-types/long-data-type](https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/data-types/long-data-type) . But var a:int64 can't be compiled with nim 32bits So, what can we use in nim to replace the long in VB? 2\. in the VB version, strings are wrapped by a function Private Function L(data As String) As String L = StrConv(data, vbUnicode) End Function hBtn = XBtn_Create(8, 30, 100, 20, L("button"), hWindow) Run How can we represented this convertor in nim? When I use string directly, the displayed characters are not what I expected. I also tried +$(string) in winimwinstr.nim, but the displayed character is wrong too. 3\. in the VB version, an argument is the address of function Public Function OnClick(ByRef bHandle As Long) As Long bHandle = True OnClick = 0 End Function XEle_RegEventC hBtn, XE_BNCLICK, AddressOf OnClick Run how can we do that in nim? Thanks
Re: wNim - Nim's Windows GUI Framework
thanks, but I will embed the grid in the GUI which has other controls, so I think ZeeGrid is not the solution. BTW, I think nim is still too young in its modules to fit my work. Maybe I made an impatient decision to learn and try to replace python yet.
Re: wNim - Nim's Windows GUI Framework
can we use something like wx.grid or wx.lib.mixins.listctrl now for a ms-Excel-like datasheet app?
Re: Is it possible to run Python code from Nim?
sorry, I mean what if we use python in nim for python's packages, for example matplotlib for plotting, sympy for symbolic calculation. It is hard for human to find and ship all dependence, so that is why pyInstaller/py2exe exists to bundle a python app for releasing.
Re: Is it possible to run Python code from Nim?
for kinds of solution, I have one question: how to compile the nim app who uses python inside, so that this app can be released to users without python on his computer
Re: release: a current-runable, error-in-the-future msgbox for wNim
I respect every contribution to Nim. But don't make conventions be a religion. ok maybe you can make it yourself's religion, but do not command all others do so. In fact, I use wxPython so I can learn wNim without too hard work. wNim is the first(and till now the only) library for me to make a little Windows GUI app quickly( where "little" means 2 aspects: 1. the released binary file has little filesize, 2. the app is simple, not too complex, but I do hope there will be more controls later or maybe examples to demostrated the existing controls). And it seems that there is no more users except me and Ward. Since nobody else uses it, wNim will develop slowly. If you can help it I appreciate you, if you can't, please let it grow without too distraction, or please coin yet anthor package As for me, I stated in the readme.md clearly that I will not use 2 spaces for indentation because it is not so obvious for my eyes. So, does that mean "hey, you should not learn/use Nim because you do not use the language's conventions"? As for me, I don't make living on coding, and I don't know much computer's jargon, So, does that mean "hey, layman, go away from programming"? Just keep focus on question itself, but not grammar of question if the question has express it clearly.This is my opinion.
[OT]if we also know basic algorithms theory, how can we get the details?
if it is too off-topic, please delete it, thanks I have old applications from whose name I think they uses LZW compression. However I checked some LZW libs(C/python/nim) but none of them yields the same output files. I think the DOS app uses different code symbols during compression. So how can we program to fetch the proper compression algorithm? Thanks the app and data files are [https://drive.google.com/open?id=1EpPs7oAUleS2xjCSqDX0rfuHkWZ0A3yU](https://drive.google.com/open?id=1EpPs7oAUleS2xjCSqDX0rfuHkWZ0A3yU) Lzw15.exe a gd_def.txt gd_def.tx_' compress a text file `Lzw15.exe e gd_def.tx_ gd_def.txt decompress a compressed file
release: a current-runable, error-in-the-future msgbox for wNim
I, a programming amateur and (always) newbie, released my msgbox control for [https://github.com/khchen/wNim](https://github.com/khchen/wNim), which can specify the font for message and buttons , at [https://github.com/retsyo/nim-myMsgBox](https://github.com/retsyo/nim-myMsgBox) I don't have much time and ( but actually) knowledge to fix its bug or inconvenience now. But it is ok for my need now. I released it in case someone has the same need or want to modify it. BTW, you may find that all my posts on this forum or github these latest days are related to my project. Thank you all for answering my question.
Re: maybe this dynamic try is not possible?
blush this is the 2nd time that I met and asked the same question these days. There is a long way for me to get familiar with Nim from a Python user view-of-point. thanks again
maybe this dynamic try is not possible?
In my function to make wFont for [https://khchen.github.io/wNim/](https://khchen.github.io/wNim/), the following 2 can work import wNim proc makeFont1(fontMessage: int): wFont {.discardable.}= var fontTmpMessage: wFont = Font(12, weight=wFontWeightBold) echo fontMessage is float echo fontMessage is int echo fontMessage is wFont if (fontMessage is float) or (fontMessage is int) : echo "in if" fontTmpMessage = Font(float fontMessage, weight=wFontWeightBold) return fontTmpMessage proc makeFont2(fontMessage:wFont): wFont {.discardable.}= var fontTmpMessage: wFont = Font(12, weight=wFontWeightBold) echo fontMessage is float echo fontMessage is int echo fontMessage is wFont if (fontMessage is wFont): echo "in if" fontTmpMessage = fontMessage return fontTmpMessage echo makeFont1(20).getPointSize() echo "\n" echo makeFont2(Font(32, weight=wFontWeightBold)).getPointSize() echo "\n" Run But when I try to combine the above into one in which the argument can be a number of the font size, or wFont. import wNim proc makeFont3(fontMessage: int|wFont): wFont {.discardable.}= var fontTmpMessage: wFont = Font(12, weight=wFontWeightBold) echo fontMessage is float echo fontMessage is int echo fontMessage is wFont if (fontMessage is float) or (fontMessage is int) : fontTmpMessage = Font(float fontMessage, weight=wFontWeightBold) else: fontTmpMessage = fontMessage echo makeFont3(40).getPointSize() echo "\n" echo makeFont3(Font(45, weight=wFontWeightBold)).getPointSize() echo "\n" Run says b2.nim(16, 15) template/generic instantiation of `makeFont3` from here b2.nim(14, 24) Error: type mismatch: got but expected 'wFont = ref wFont:ObjectType' Run
Re: Error: implicit object field construction requires a .partial object, but got wMyFrame:ObjectType
Aha, thanks. I have just found [https://github.com/jyapayne/nim-extensions](https://github.com/jyapayne/nim-extensions) and rewrite the code. Now it seems that there is no much difference between nim-extensions version and your type version, but nim-extensions version can be understood easily for me since I have some Python background. BTW, it seems that there is a direct way to declare static class member as [https://stackoverflow.com/questions/68645/are-static-class-variables-possible](https://stackoverflow.com/questions/68645/are-static-class-variables-possible) said import wNim import extensions/oop class MyFrame of RootObj: var title: string frame: wFrame panel: wPanel bt1, bt2: wButton clicked: int method init*(title: string) {.base.}= self.frame = Frame(title=title) self.panel = Panel(self.frame) self.bt1 = Button(self.panel, label="1", pos=(0, 0)) self.bt2 = Button(self.panel, label="2", pos=(100, 0)) self.frame.wEvent_Close do (event: wEvent): event.veto() self.bt1.wEvent_Button do (event: wEvent): self.frame.endModal() self.frame.close() self.clicked = 1 self.bt2.wEvent_Button do (event: wEvent): self.frame.endModal() self.frame.close() self.clicked = 2 method show: int {.base, discardable.} = self.frame.showModal() return self.clicked when isMainModule: let app = App() let frame = Frame(title="main", style=wDefaultFrameStyle) bt = Button(frame, label = "click") bt.wEvent_Button do (event: wEvent): let myframe = new MyFrame(title: "Hello World") res = myframe.show() echo res frame.center() frame.show() app.mainLoop() Run
Re: why var can not be declared this way?
thanks anyone. I am using python in which def f(size=1): if size == 1: widFrame = 320 hiFrame = 200 else: widFrame = 3200 hiFrame = 2000 print(widFrame, hiFrame) f() Run will says 320 200 Run so this is the difference between them
Error: implicit object field construction requires a .partial object, but got wMyFrame:ObjectType
I try to make a control type in [https://khchen.github.io/wNim/](https://khchen.github.io/wNim/), so I modified the examples coming with wNim. The control will work like this: after click any of the 2 buttons on the frame, the frame will be closed, and a number will be returned to tell which button has been clicked. However, the code will not be compiled due to subclassing.nim(16, 13) Error: implicit object field construction requires a .partial object, but got wMyFrame:ObjectType Run On the other hand, if I only write bt1 and bt2 without self. before them, I get subclassing.nim(27, 5) Error: undeclared identifier: 'bt1' Run I think I must misunderstand the type in nim, please correct me, thanks {.this: self.} import wNim type wMyFrame = ref object of wFrame proc final(self: wMyFrame) = wFrame(self).final() proc init(self: wMyFrame, title: string) = wFrame(self).init(title=title, size=(350, 200)) center() var panel = Panel(self) bt1 = Button(panel, label="1", pos=(0, 0)) bt2 = Button(panel, label="2", pos=(100, 0)) self.wEvent_Close do (event: wEvent): let dlg = MessageDialog(self, "Do you really want to close this application?", "Confirm Exit", wOkCancel or wIconQuestion) if dlg.showModal() != wIdOk: event.veto() proc show(self: var wMyFrame): int {.discardable.} = bt1.wEvent_Button do (event: wEvent): self.endModal() self.close() return 1 bt2.wEvent_Button do (event: wEvent): self.endModal() self.close() return 2 proc MyFrame(title: string): wMyFrame {.inline.} = new(result, final) result.init(title) when isMainModule: let app = App() let frame = MyFrame("Hello World") var res = frame.show() app.mainLoop() Run
I don't know whether this problem lies in nim or wNim?
In my question, some buttons are created by amount given by parameter numOfButtons. When a button is clicked, its holder frame is closed and the index( begins from 0) is returned. But I found that no matter which button is clicked, only the last(in the case of numOfButtons==3, the last index is 2) is returned. So what is the problem? Thanks import winim/com import wNim proc msgBox(numOfButtons:int = 1): int {.inline, discardable.} = let frame = Frame( title="test" ) panel = Panel(frame) (widPanel, hiPanel) = panel.getClientSize() sizeButton = (int(widPanel/6), hiPanel) yDistance = 10 var tmpButton: wButton (lastX, lastY) = (0, 0) clicked:int = 0 for idxButton in 0 .. (numOfButtons-1): tmpButton = Button(panel, label="b" & $idxButton, pos=(lastX, lastY), size=sizeButton ) tmpButton.wEvent_Button do (event: wEvent): clicked = idxButton frame.endModal() frame.close() lastX += sizeButton[0] + yDistance frame.center() frame.showModal() return clicked var app = App() frame = Frame() var f = msgBox(numOfButtons=3) echo "pressed button ", f frame.center() frame.show() app.mainLoop() Run
why var can not be declared this way?
for proc f(size=1) = if size == 1: var widFrame = 320 hiFrame = 200 else: var widFrame = 3200 hiFrame = 2000 echo (widFrame, hiFrame) f() Run I get t_bug.nim(11, 11) Error: undeclared identifier: 'widFrame' Run Why? I know there is a solution proc f(size=1) = var widFrame:int = 0 hiFrame:int = 0 if size == 1: (widFrame, hiFrame) = (320, 200) else: (widFrame, hiFrame) = (3200, 2000) echo (widFrame, hiFrame) f() Run but in fact widFrame and hiFrame should be read-only if the parameter size is given, what I expect is proc f(size=1) = if size == 1: var widFrame = 320 hiFrame = 200 else: var widFrame = 3200 hiFrame = 2000 echo (widFrame, hiFrame) f() Run which of cause failed with message t_bug.nim(11, 11) Error: undeclared identifier: 'widFrame'. What is the solution for this case? Thanks
Re: how to make a resource file for nim on windows?
finally I found that wNim.res is actually obj file which can be read by ld of GCC, not res file we can make it by wnim.rc wnim.o cp wnim.o wnim.res Run
how to make a resource file for nim on windows?
In fact, I am using [https://khchen.github.io/wNim](https://khchen.github.io/wNim)/ with my nim 64 bits. All demos compile and run without problem In some of the demo files, there is a line {.passL: "wnim.res" .} Run which use a 32,468 bytes wnim.res But I found that no matter I use GoRc or ResourceHacker, the following wNim.rc file( which actually comes in wNim too) 1000 ICON "images\\wNim.ico" Run can produce wnim.res file with different size for example GoRC.exe /r /machine X64 wNim.rc Run creates a 32,222 bytes wNim.res But when I try to compile the wNim's demo with the new wNim.res, I get Hint: [Link] wnim.res: file not recognized: File format not recognized collect2.exe: error: ld returned 1 exit status Error: execution of an external program failed: 'gcc.exe -mwindows -o R:\a\main.exe C:\Users\USER\.nimble\pkgs\winim-2.5.1\winim\inc\..\lib\wini... C:\Users\USER\nimcache\main_r\mydata.c.o wnim.res ' Run any help? thanks
what makes the 0.18.1-compiled binary file larger than 0.18.0-compiled binary file
on my Msys2 + Mingw64 on Win7 64 bits, even echo 1 gives different filesize when the same -d:release are used. So what makes the difference and how to strip down besides strip/upx? source,0.18.0 0.18.1(git cloned) echo 1, 462,025 462,238 demo.nim from wnim 1,014,498 1,024,475 scribble.nim from wnim901,233 909,836 Run
is there computer algebra system module?
is there a module just like what [https://www.sympy.org](https://www.sympy.org)/ does? sympy has a long list of feature here: [https://www.sympy.org/en/features.html](https://www.sympy.org/en/features.html) thanks
do regular expression on unicode string?
import re import unicode var txt = "自我 我们 我" # this is actually read from external file #~ txt = txt.toRunes() # type mismatch: got but expected 'string' var result = txt.findall(re".{0,1}我.{0,1}") for i in result: echo i # "自我", "我们", "我" are expected Run will display ▒我 我▒ 我 Run as the code says, if I convert txt to runes, then the txt.findall says "type mismatch: got but expected 'string'". But the above code does not find the whole unicode characters around "我" which is not right answer So any suggestion? Thanks
is space around "==" the part of syntax?
echo 1 == 0 # space in the beginning and end of == echo 1==0 # no space Run can be compiled and run without warning/error however echo 1== 0 Run can be compiled and run as expected, but there is a warning ` Warning: Number of spaces around '==' is not consistent [Spacing]` the most strange is that nim refuses to compile echo 1 ==0 Run and says Error: type mismatch: got but expected one of: proc `==`(x, y: float): bool proc `==`(x, y: int64): bool proc `==`[T](x, y: ptr T): bool proc `==`(x, y: int): bool proc `==`(x, y: string): bool proc `==`[T: proc](x, y: T): bool proc `==`[T](x, y: ref T): bool proc `==`[T: SomeUnsignedInt](x, y: T): bool proc `==`(x, y: bool): bool proc `==`(x, y: char): bool proc `==`[T](x, y: seq[T]): bool proc `==`[T: tuple | object](x, y: T): bool proc `==`[Enum: enum](x, y: Enum): bool proc `==`(x, y: float32): bool proc `==`(x, y: int8): bool proc `==`(x, y: int32): bool proc `==`(x, y: int16): bool proc `==`(x, y: cstring): bool proc `==`[T](x, y: set[T]): bool proc `==`(x, y: pointer): bool proc `==`[I, T](x, y: array[I, T]): bool expression: ==0 Run
Re: how to declare global variant in one proc
thanks, I don't mean to export word from module which is the next step currently, what I met is that the following command line version cannot be compiled, R:\CheckIt.nim(709, 5) Error: undeclared identifier: 'word' Run because there is no global variant word so checkHeading and checkPunctation can not find it # I am command line version proc checkHeading() = word.Selection.HomeKey(...) # **this line can't find variant word, so the compilation can't succeed** do some check on Heading, then display message proc checkPunctation() = word.Selection.HomeKey(...) do some check on punctaion, then display message proc check(fn)= var word = CreateObject("Word.Application") # how to declare a global `word` as the python version does? word.Documents.Open(fn, True) checkHeading() checkPunctation() when isMainModule: check(r"c:\test.doc") Run
how to declare global variant in one proc
In my situation, I translate a python code into nim # I am cli.py def checkHeading(): word.Selection.HomeKey(Unit=win32com.client.constants.wdStory, Extend=win32com.client.constants.wdMove) do some check on Heading, then display message def checkPunctation(): word.Selection.HomeKey(Unit=win32com.client.constants.wdStory, Extend=win32com.client.constants.wdMove) do some check on punctaion, then display message def check(fn): global word word = win32com.client.gencache.EnsureDispatch("Word.Application") word.Documents.Open(FileName=fn, ReadOnly=True) checkHeading() checkPunctation() if __name__ == '__main__': check(r'c:\test.doc') Run As you can see, there is global variant word in function check, and this variant can be used in other functions So I can write the GUI app by using cli.py as module there is button to choose and open file then redirect stdout to gui text-control Run how ever, in nim even I use var word {.**global**.} = CreateObject("Word.Application") Run in proc check, I still get R:CheckIt.nim(709, 5) Error: undeclared identifier: 'word' so is there real python-like global solution except proc checkHeading() = word.Selection.HomeKey(...) do some check on Heading, then display message proc checkPunctation() = word.Selection.HomeKey(...) do some check on punctaion, then display message proc check(fn): word.Documents.Open(fn, True) checkHeading() checkPunctation() var word = CreateObject("Word.Application") Run
Re: Winim - Nim's Windows API and COM Library
Thanks for updating one question: how to read COM object's constants? In python, we can do import win32com.client word = win32com.client.gencache.EnsureDispatch("Word.Application") print(win32com.client.constants.wdLineSpaceExactly) word.Quit() Run but in winim, none of the following is right import winim.com comScript: #~ if true: let word = CreateObject("Word.Application") #~ echo (com.client.constants.wdLineSpaceExactly) echo "undeclared identifier: 'client'" #~ echo (client.constants.wdLineSpaceExactly) echo "undeclared identifier: 'client'" #~ echo (constants.wdLineSpaceExactly) echo "undeclared identifier: 'constants'" #~ echo (wdLineSpaceExactly) echo "undeclared identifier: 'wdLineSpaceExactly'" #~ echo (word.wdLineSpaceExactly) echo "unhandled exception: unsupported method: wdLineSpaceExactly [COMError]" word.Quit() COM_FullRelease() Run Thnaks
strange copyFile
I am using Nim Compiler Version 0.17.2 (2017-09-10) [Windows: amd64] with MSYS2+MingW64 on Win7 64 bits. I know test:test.txt is not a valid DOS/Windows filename. So how to detect it in code? Thanks import os try: copyFile("test.txt", "test:test.txt") except: echo "not support" # this will not happend if existsFile("test:test.txt"): echo "ok"# this happends because a zero-byte test file is created and treated else: echo "no" the output is ok and a zero-byte test file is created
Re: Nim image libraries
not an image one: [https://github.com/nim-lang/cairo](https://github.com/nim-lang/cairo)
Re: Nim image libraries
# [https://github.com/barcharcraz/nim-freeimage](https://github.com/barcharcraz/nim-freeimage) a nimrod wrapper for FreeImage Latest commit 695e4d4 on Apr 22 2014 # [https://github.com/barcharcraz/nimlibpng](https://github.com/barcharcraz/nimlibpng) nimrod wrapper for libpng Latest commit 7964c76 on Aug 4 2014
Re: Nim vs D
I am using mingw64/clang64 in Msys2. But I found that the exe file build by clang runs very slower than exe by gcc. The nim is a fresh build from github source yesterday $ nim Nim Compiler Version 0.17.1 (2017-07-07) [Windows: amd64] Copyright (c) 2006-2017 by Andreas Rumpf for the mentioned nim file (a.nim) proc fibonacci(n: int): float = if n < 2: result = float(n) else: result = fibonacci(n-1) + fibonacci(n-2) echo fibonacci(50) first, for cc = gcc in nim.cfg $ gcc --version gcc.exe (Rev2, Built by MSYS2 project) 6.2.0 Copyright (C) 2016 Free Software Foundation, Inc. $ nim c -d:release --out:a_gcc.exe a.nim $ du -b ./a_gcc.exe 457546 ./a_gcc.exe $ time ./a_gcc.exe 12586269025.0 real0m5.164s user0m0.015s sys 0m0.015s Then use cc = clang in nim.cfg $ clang --version clang version 3.9.1 (tags/RELEASE_391/final) Target: x86_64-w64-windows-gnu Thread model: posix InstalledDir: E:\msys64\mingw64\bin $ nim c -d:release --out:a_clang.exe a.nim $ du -b ./a_clang.exe 423480 ./a_clang.exe $ time ./a_clang.exe 12586269025.0 real2m2.055s user0m0.000s sys 0m0.015s
Re: Nim for Windows: MinGW vs TDM-GCC
2\. gpu/cuda program, because there is no(?) file.a for mingw under windows for example [https://github.com/unicredit/nimcuda](https://github.com/unicredit/nimcuda) $ cd /r/nimcuda-master/examples/ $ nim c -r fft.nim --cincludes:"/r/nimcuda-master/c2nim" CC: nimcuda_cuComplex R:\nimcuda-master\examples\nimcache\nimcuda_fft.c:202:97: error: unknown type name 'float2' typedef N_CDECL_PTR(cufftResult_CsvnaTViXJFbqo9bM6i9bROw, TY_HpGapddEWLlYAX7BuEE4qA) (int plan, float2* idata, float2* odata, int direction); ^~ ... R:\nimcuda-master\examples\nimcache\stdlib_system.c:12829:3: error: unknown type name 'float2' float2 value; ^~ Hint: [Link] gcc.exe: error: R:\nimcuda-master\examples\nimcache\nimcuda_fft.o: No such file or directory gcc.exe: error: R:\nimcuda-master\examples\nimcache\stdlib_system.o: No such file or directory gcc.exe: error: R:\nimcuda-master\examples\nimcache\nimcuda_cufft.o: No such file or directory gcc.exe: error: R:\nimcuda-master\examples\nimcache\nimcuda_cuComplex.o: No such file or directory gcc.exe: error: R:\nimcuda-master\examples\nimcache\nimcuda_vector_types.o: No such file or directory Error: execution of an external program failed: 'gcc.exe -o R:\nimcuda-master\examples\fft.exe R:\nimcuda-master\examples\nimcache\nimcuda_fft.o R:\nimcuda-master\examples\nimcache\stdlib_system.o R:\nimcuda-master\examples\nimcache\nimcuda_cufft.o R:\nimcuda-master\examples\nimcache\nimcuda_cuComplex.o R:\nimcuda-master\examples\nimcache\stdlib_math.o R:\nimcuda-master\examples\nimcache\nimcuda_vector_types.o R:\nimcuda-master\examples\nimcache\nimcuda_library_types.o R:\nimcuda-master\examples\nimcache\nimcuda_cuda_runtime_api.o R:\nimcuda-master\examples\nimcache\nimcuda_driver_types.o R:\nimcuda-master\examples\nimcache\nimcuda_surface_types.o R:\nimcuda-master\examples\nimcache\nimcuda_texture_types.o R:\nimcuda-master\examples\nimcache\nimcuda_nimcuda.o R:\nimcuda-master\examples\nimcache\nimcuda_cublas_api.o R:\nimcuda-master\examples\nimcache\nimcuda_cublas_v2.o R:\nimcuda-master\examples\nimcache\nimcuda_cuda_occupancy.o R:\nimcuda-master\examples\nimcache\nimcuda_cudnn.o R:\nimcuda-master\examples\nimcache\nimcuda_curand.o R:\nimcuda-master\examples\nimcache\nimcuda_cusolver_common.o R:\nimcuda-master\examples\nimcache\nimcuda_cusolverDn.o R:\nimcuda-master\examples\nimcache\nimcuda_cusolverRf.o R:\nimcuda-master\examples\nimcache\nimcuda_cusolverSp.o R:\nimcuda-master\examples\nimcache\nimcuda_cusparse.o R:\nimcuda-master\examples\nimcache\nimcuda_nvblas.o R:\nimcuda-master\examples\nimcache\nimcuda_nvgraph.o
Re: Nim for Windows: MinGW vs TDM-GCC
I am using Msys2 + Mingw64 on win7 64 bits. Almost everything is ok, except: 1\. for blas, for exampe [https://forum.nim-lang.org/t/3029](https://forum.nim-lang.org/t/3029) $ cd /r/arraymancer/tests/ $ nim c -r test_operators_blas Hint: [Link] Hint: operation successful (27703 lines compiled; 8.213 sec total; 208.863MiB peakmem; Debug Build) [SuccessX] Hint: R:\arraymancer\tests\test_operators_blas.exe [Exec] could not import: cblas_sscal Error: execution of an external program failed: 'R:\arraymancer\tests\test_operators_blas.exe '
Re: The Nim Language Manual
so what is the source file for [https://nim-lang.org/docs/manual.html](https://nim-lang.org/docs/manual.html)? I looked into the nim's source but only found pure txt file
Re: How to sort tuples?
can sortedbyit support optional "reversed" arguement? currently, if I only knew the 2-steps method: var people3 =people1.sortedByIt(it.name) var people4 = people3.reversed() echo people4 I don't konw whether the above implementation is high effiency. what if an inner way like this var people4 =people1.sortedByIt(it.name, True) echo people4
Re: progress while binding libxl
Thanks, LeuGim. **`When`** does work. However [https://nim-lang.org/docs/manual.html#statements-and-expressions-when-statement](https://nim-lang.org/docs/manual.html#statements-and-expressions-when-statement) still be Greek for me. * * * more question I, a lazy none programmer practitioner, met: How to make an auto-converted type? Sorry, I don't know its exact name. I will explain it as folows: for example, in the original functions in DLL, Widecstring type arg is need. So the actual code should be proc original_Clang_FunctionA(value: Widecstring) {.cdecl, importc: "functon1", dynlib: xldll}. ... proc original_Clang_FunctionZ(value: Widecstring) {.cdecl, importc: "functon26", dynlib: xldll}. var value1 = newWideCString(convert("你好", "utf8", "gb2312")) original_Clang_FunctionA(value1) or we can make a function proc s(val: string|Widecstring): Widecstring = when not type(val) is Widecstring: return newWideCString(convert(val, "utf8", "gb2312")) else: return val then user writes original_Clang_FunctionA("你好".s) ... original_Clang_FunctionZ("世界".s) ... both are tedious for user. So We can wrap the DLL function like this: proc original_Clang_FunctionA(value: Widecstring) {.cdecl, importc: "functon26", dynlib: xldll}. proc FunctionA(value: string|Widecstring) = var value1 = value when not type(value1) is Widecstring: value1 = newWideCString(convert(value1, "utf8", "gb2312")) original_Clang_FunctionA(value1) then the user only need to write in a clean way: FunctionA("你好") However the problem is that we have to supply every wrapped functions for so many functions, which is a repetitive work for library supplier. So if there is something like this type someString from object(string|Widecstring) = when not type(someString) is Widecstring: someString.value = newWideCString(convert(value1, "utf8", "gb2312")) someString.type = Widecstring proc FunctionA(value: someString) {.cdecl, importc: "functon1", dynlib: xldll}. ... proc FunctionZ(value: someString) {.cdecl, importc: "functon26", dynlib: xldll}. and the user only writes like before FunctionA("你好") ... FunctionA("世界") is this possible? Thanks
Re: echo proper string in different consoles?
thanks but set cp936 seems do not work in msys2 [https://github.com/zacharycarter/blt-nim](https://github.com/zacharycarter/blt-nim) may be a solution for simple console-like interactive
Re: progress while binding libxl
thanks, and I found echo type("text") is string
Re: progress while binding libxl
this is what I get currently. Most functions in libxl can be exposed in the same way But something still puzzled me, or I have not know yet in nim: 1. for xlBookAddSheetW, the last arg is SheetHandle initSheet actually. But I used int. How to cast a number to SheetHandle? 2. how to judge the type is cstring or widecstring, so I can convert cstring to widecstring import encodings type tagBookHandle* {.final, header: "", importc: "struct tagBookHandle".} = object BookHandle* = ptr tagBookHandle type tagSheetHandle* {.final, header: "", importc: "struct tagSheetHandle".} = object SheetHandle* = ptr tagSheetHandle const NUMFORMAT_DATE = 14 const xldll* = "libxl.dll" proc xlCreateBookCW*(): BookHandle {.cdecl, importc: "xlCreateBookCW", dynlib: xldll.} #~ proc xlBookAddSheetW*(handle: BookHandle; name: cstring; initSheet: SheetHandle): SheetHandle {.cdecl, #~ importc: "xlBookAddSheetW", dynlib: xldll.} proc xlBookAddSheetW*(handle: BookHandle, name: cstring, initSheet: int): SheetHandle {.cdecl, importc: "xlBookAddSheetW", dynlib: xldll.} proc xlSheetWriteStrW*(handle: SheetHandle; row: cint; col: cint; value: Widecstring; format: cint): cint {.cdecl, importc: "xlSheetWriteStrW", dynlib: xldll, discardable.} proc xlBookSaveW*(handle: BookHandle; filename: Widecstring): cint {.cdecl, importc: "xlBookSaveW", dynlib: xldll, discardable.} proc xlBookReleaseW*(handle: BookHandle) {.cdecl, importc: "xlBookReleaseW", dynlib: xldll.} var book = xlCreateBookCW() if not book.isnil: var sheet = xlBookAddSheetW(book, "Sheet1", 0); if not sheet.isnil: xlSheetWriteStrW(sheet, cint(2), cint(1), newWideCString(convert("你好!", "utf8", "gb2312")), cint(0) ); if not (xlBookSaveW(book, newWideCString(convert("测试.xls", "utf8", "gb2312")))==0): echo "\nFile example.xls has been created.\n"; xlBookReleaseW(book);
Re: progress while binding libxl
the first question, I translated typedef struct tagBookHandle * BookHandle; to type tagBookHandle* {.final, incompleteStruct, importc: "tagBookHandle".} = object BookHandle* {.importc: "BookHandle".} = ptr tagBookHandle Am I right? But why I get unknown type name 'tagBookHandle' when I compile the following simple code type tagBookHandle* {.final, incompleteStruct, importc: "tagBookHandle".} = object BookHandle* {.importc: "BookHandle".} = ptr tagBookHandle const xldll* = "libxl.dll" # BookHandle xlCreateBookCW(void); proc xlCreateBookCW*(): BookHandle {.cdecl, importc: "xlCreateBookCW", dynlib: xldll.}
progress while binding libxl
This post is related to [https://forum.nim-lang.org/t/2977/2](https://forum.nim-lang.org/t/2977/2), in which I said "For commercial products to read/write XLS/XLSX, I found [http://libxl.com/](http://libxl.com/)" So I started this binding work on June 18th 2017. However I am totally newbee in fact of Nim and I have not so much free time, so 1\. the progress may be very very slow. If someone are willing to finish the binding himself, you are welcome 2\. there may be very lots of, even very stupid, questions
Re: echo proper string in different consoles?
actually I have tested getCurrentEncoding, which gives gb2312 in both msys and DOS as Araq says. So what is the solution?
echo proper string in different consoles?
I am a Chinese Windows user. I use Msys2+Mingw64 (export LANG="EN.UTF-8") to compile nim app. But I also use windows7 DOS console(the default codepage is cp936, which is almost gb2312). The following code performs different in msys2 and windows's console. So my question, how to let the EXE echo properly no matter in whatever consoles? Thanks # this file is saved as a UTF8 file import future, encodings # this line outputs "你好" in msys which is corrected. # but "浣犲ソ" in windows' console which is wrong echo "你好" # this outputs "▒▒▒" in msys which is wrong. # but "你好" in DOS which is corrected echo convert("你好", "gb2312", "utf8")
Re: package like python's pandas?
As far as I know, there is no nim wrapper for libxlsxwriter. The "Interfacing C and Nim" and "Converting C code to Nim" part on [https://github.com/nim-lang/Nim/wiki/Nim-for-C-programmers](https://github.com/nim-lang/Nim/wiki/Nim-for-C-programmers) may be useful. As for reading XLS, I found [http://libxls.sourceforge.net](http://libxls.sourceforge.net)/ For commercial products to read/write XLS/XLSX, I found [http://libxl.com](http://libxl.com)/ All the above lib are for C.
Re: package like python's pandas?
As for writing excel XLSX file, a C lib [https://libxlsxwriter.github.io](https://libxlsxwriter.github.io)/ maybe useful
Re: package like python's pandas?
Yes, I mean DOCX (not XLSX) because my work is a part of whole project. My tabular data with specialed format will be mixed with materials(text, data, graphics etc) supplied by other people. So sorry to continue discuss here because I found this forum is different so that I can't find a way to send private message