00:02:39 | FromDiscord | <sOkam! 🫐> looks like im in for a rough debugger C-side stepping session for the next few days ⚰️ |
00:05:35 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GAl |
00:06:32 | FromDiscord | <Elegantbeef> `r.swapChain.cfg.addr.isNil` is funny |
00:06:36 | FromDiscord | <Elegantbeef> It'll never be nil |
00:06:49 | FromDiscord | <sOkam! 🫐> yeah, but how do i check for nil in those things? |
00:06:59 | FromDiscord | <Elegantbeef> I don't know what `cfg` is |
00:07:01 | FromDiscord | <Elegantbeef> Is it a struct |
00:07:03 | FromDiscord | <Elegantbeef> A ref |
00:07:05 | FromDiscord | <sOkam! 🫐> i just don't know whats crashing |
00:07:10 | FromDiscord | <sOkam! 🫐> its an object |
00:07:28 | FromDiscord | <Elegantbeef> Objects cannot be nil so that check is odd |
00:07:36 | FromDiscord | <sOkam! 🫐> yeah its random stuff |
00:07:45 | FromDiscord | <sOkam! 🫐> idk whats crashing, just threw crap to the wall |
00:08:07 | FromDiscord | <Elegantbeef> `r.swapChain.cfg.addr` is where I'd say it's likely to be seg faulting |
00:08:34 | FromDiscord | <sOkam! 🫐> what could cause that object to be optimized away? |
00:08:42 | FromDiscord | <Elegantbeef> what does that create proc expect |
00:08:43 | FromDiscord | <Elegantbeef> like the implementation |
00:08:54 | FromDiscord | <sOkam! 🫐> an addr of the swapchain descriptor |
00:08:57 | FromDiscord | <Elegantbeef> The implication is that it is getting optimised away |
00:09:30 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GAn |
00:09:49 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GAo |
00:11:37 | FromDiscord | <Elegantbeef> What do the docs say for `wgpuDeviceCreateSwapChain` |
00:14:55 | FromDiscord | <sOkam! 🫐> err... i cannot find it 🧩 |
00:15:40 | FromDiscord | <Elegantbeef> Well I've done all that can be done |
00:16:26 | FromDiscord | <sOkam! 🫐> idk rust, but this is what it does↵https://github.com/gfx-rs/wgpu-native/blob/2773864b0b34bb6a5656ca815cad22c45a99154f/src/lib.rs#L2392-L2420 |
00:16:48 | FromDiscord | <Elegantbeef> Uhh |
00:17:00 | FromDiscord | <Elegantbeef> `Option<T>` is not `ptr SwapChainDescriptor` |
00:17:51 | FromDiscord | <Elegantbeef> Your third argument is not the right type, so that this worked at all is amazing |
00:19:24 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GAr |
00:19:52 | FromDiscord | <Elegantbeef> I mean we found the issue |
00:20:12 | FromDiscord | <Elegantbeef> You're passing a `ptr T` to something expecting `RustOption[ptr T]` |
00:20:50 | FromDiscord | <sOkam! 🫐> In reply to @Elegantbeef "You're passing a `ptr": https://github.com/webgpu-native/webgpu-headers/blob/8e9025e0fa4b33d5e7cc682b7604b021b29f36c6/webgpu.h#L1648 |
00:21:04 | FromDiscord | <sOkam! 🫐> not really? or am I missing something huge? |
00:21:18 | FromDiscord | <Elegantbeef> Look at `descriptor` |
00:21:19 | FromDiscord | <sOkam! 🫐> like... wouldn't that mean the app crashes -allways? |
00:21:21 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4GAt |
00:21:22 | FromDiscord | <Elegantbeef> It's an `Option[T]` |
00:21:35 | FromDiscord | <sOkam! 🫐> yeah... but its working normally without --debugger:native |
00:21:46 | FromDiscord | <sOkam! 🫐> the app resizes without issues |
00:22:01 | FromDiscord | <Elegantbeef> I mean nice, but what is Rust's implementation of `Option<&T>` |
00:22:03 | FromDiscord | <sOkam! 🫐> and I mapped the C headers, which say that it is a ptr Struct |
00:22:14 | FromDiscord | <ravinder387> sent a code paste, see https://play.nim-lang.org/#ix= |
00:22:27 | FromDiscord | <Elegantbeef> If Rust's option does what Nim's do then it's probably fine to treat it as a pointer |
00:22:30 | FromDiscord | <ravinder387> is it enough command to create production code |
00:22:36 | FromDiscord | <Elegantbeef> If Rust's options do not do what Nim's do it's not ok |
00:22:44 | FromDiscord | <Elegantbeef> `-d:release -d:lto` are more like it |
00:23:06 | FromDiscord | <Elegantbeef> Nim's options turns pointer types into a wrapped sentinel value where `nil` is invalid |
00:23:26 | FromDiscord | <Elegantbeef> I do not know why the debugger changes the behaviour, like I said all I know indicates it shouldnt |
00:23:43 | FromDiscord | <Elegantbeef> But i'm pointing you to where a problem may exist |
00:25:08 | FromDiscord | <sOkam! 🫐> @beef https://stackoverflow.com/a/39007323 |
00:25:22 | FromDiscord | <sOkam! 🫐> apparently its just a nullable pointer in terms of the FFI |
00:25:39 | FromDiscord | <Elegantbeef> Right then the ABI means a pointer is fine |
00:26:00 | FromDiscord | <sOkam! 🫐> yeah, otherwise it wouldn't work |
00:26:19 | FromDiscord | <sOkam! 🫐> also, running with `RUST_BACKTRACE=1` doesn't trigger anything, which means that rust code is not even reached |
00:26:27 | FromDiscord | <sOkam! 🫐> its crashing on the nim+c side |
00:27:36 | FromDiscord | <Elegantbeef> Compile with `-d:useMalloc --debugger: native` and run it throw valgrind |
00:28:21 | FromDiscord | <Elegantbeef> through\ |
00:30:15 | FromDiscord | <sOkam! 🫐> what do I track, if --debugger:native does not fail? |
02:31:20 | FromDiscord | <millymox> Trying to make a command line tool, does nim have a command line parser? |
02:32:59 | FromDiscord | <Elegantbeef> There are a bunch there is parseopt in the stdlib and then many on nimble |
02:34:14 | NimEventer | New Nimble package! unicody - An alternative / companion to std/unicode, see https://github.com/guzba/unicody |
02:39:19 | * | xmachina joined #nim |
04:35:25 | * | rockcavera quit (Remote host closed the connection) |
05:07:47 | FromDiscord | <sOkam! 🫐> Can nimc compile code directly from a string in cli, instead of from a file? |
05:12:37 | FromDiscord | <nasuray> In reply to @millymox "Trying to make a": cligen is my preference for cli |
05:24:09 | FromDiscord | <Phil> In reply to @ShalokShalom (ShalokShalom) "Why would you consider": Because it is implementing an entire new logic space that you need to learn.↵It is a gargantuan "you just gotta know this" field. And you need to translate the DSL and that may have not that easy to see logic errors attached.↵It is a last resort when the complexity of your problem domain is so intimidating you need to tame it somehow that isn't code because you lose o |
05:30:19 | FromDiscord | <nnsee> In reply to @heysokam "Can nimc compile code": maybe something like `nim c <(echo 'echo "hello world"')` |
05:32:56 | FromDiscord | <sOkam! 🫐> In reply to @nnsee "maybe something like `nim": i honestly doubt that works across platforms |
05:33:12 | FromDiscord | <sOkam! 🫐> considering `cd folder; command` breaks on windows 🤷♂️ |
05:34:31 | FromDiscord | <nnsee> oh definitely not lol |
05:35:03 | FromDiscord | <nnsee> i mean there is also the `eval` flag |
05:35:15 | FromDiscord | <nnsee> which can evaluate straight from the command line |
05:35:41 | FromDiscord | <sOkam! 🫐> im trying to shortcut the fact that `gorge, gorgeEx` are the only ways to run a command in cli from the VM (like inside the nimc processing of a file)... by actually compiling a file that just does `execShellCmd( args.join(" ") )` |
05:36:09 | FromDiscord | <sOkam! 🫐> because the VM itself doesnt not have shell executing |
05:36:36 | FromDiscord | <sOkam! 🫐> (edit) "because the VM itself doesnt not have shell executing ... " added "without eating the output into a buffer and not showing it in stdout" |
05:37:57 | FromDiscord | <sOkam! 🫐> so was thinking of something like `nim c --outDir:someDir "mycode; otherline; other"` or similar, without needing a second intermediate step of writing a code file somewhere |
05:38:31 | FromDiscord | <nnsee> what are you trying to do |
05:38:51 | FromDiscord | <nnsee> in the grander scheme of things |
05:38:57 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GBl |
05:39:04 | FromDiscord | <sOkam! 🫐> there is no execshellcmd in the VM |
05:39:39 | FromDiscord | <sOkam! 🫐> only gorge/gorgeEx which eat the output for themselves, and the console just freezes while cargo is running to build the static lib which the compiled project depends on |
05:40:02 | FromDiscord | <sOkam! 🫐> then all of a sudden the entire output of cargo is printed all at once to console, when its done |
05:42:17 | FromDiscord | <odexine> https://nim-lang.org/docs/nimscript.html#exec%2Cstring ? |
05:43:27 | FromDiscord | <nnsee> yeah i feel like there are like a dozen variations of this for nimble |
05:49:31 | FromDiscord | <nnsee> or just a few |
06:08:45 | FromDiscord | <sOkam! 🫐> In reply to @odexine "https://nim-lang.org/docs/nimscript.html#exec%2Cstr": exec does not work on the vm |
06:09:15 | FromDiscord | <odexine> ???? |
06:09:21 | FromDiscord | <odexine> it says right there "nimscript" |
06:09:38 | FromDiscord | <sOkam! 🫐> this is not `when defined(nimscript)` its `when nimvm` |
06:09:53 | FromDiscord | <odexine> what context are you even in right now |
06:10:19 | FromDiscord | <sOkam! 🫐> this https://github.com/heysokam/wgpu/blob/4f23d2f7fe2fb93b8b432e14a27cfdc31e973279/src/wgpu/compile.nim#L24 |
06:10:33 | FromDiscord | <sOkam! 🫐> which runs this:↵https://github.com/heysokam/wgpu/blob/4f23d2f7fe2fb93b8b432e14a27cfdc31e973279/src/wgpu/compile.nim#L54-L55 |
06:15:00 | FromDiscord | <odexine> wouldnt this be better in a nim config file |
06:15:29 | FromDiscord | <odexine> let me think |
06:19:13 | FromDiscord | <sOkam! 🫐> I tried my best to make it work in nimble |
06:19:45 | FromDiscord | <sOkam! 🫐> if you have a way to do it let me know, but I failed with everything I tried and resorted to just use a static block instead |
06:20:17 | FromDiscord | <sOkam! 🫐> because otherwise the only other solution I saw was to send the complexity of the buildsystem to the user, which is a really crappy solution |
06:20:49 | FromDiscord | <odexine> you can always do what piconim did and have a builder binary |
06:21:20 | FromDiscord | <sOkam! 🫐> or just have a shell-runner binary that can exec from nimvm |
06:21:48 | FromDiscord | <sOkam! 🫐> ideally there should just be an exec or execshellcmd version inside the vm |
06:21:50 | FromDiscord | <sOkam! 🫐> (edit) "vm" => "nimvm" |
06:22:09 | FromDiscord | <sOkam! 🫐> since the functionality is already there for gorge |
06:38:49 | * | ntat joined #nim |
07:51:10 | FromDiscord | <pk.kyle> any quick and handy gui framework that lets me generate latex |
07:51:19 | FromDiscord | <pk.kyle> i dont want my math equations to look shit \:( |
07:51:31 | * | FromDiscord quit (Remote host closed the connection) |
07:51:44 | * | FromDiscord joined #nim |
07:57:03 | * | Mister_Magister quit (Read error: Connection reset by peer) |
07:58:51 | * | Mister_Magister joined #nim |
07:59:45 | FromDiscord | <Phil> In reply to @pk.kyle "any quick and handy": As in, that renders latex visually or as in a way to generate latex notation? |
07:59:53 | FromDiscord | <pk.kyle> former |
08:01:08 | FromDiscord | <Phil> https://xigoi.srht.site/matext/ might fit the bill.↵Haven't used it myself but I don't use Latex generally |
08:01:53 | FromDiscord | <pk.kyle> oh thx |
08:02:40 | FromDiscord | <Phil> Other than that you can always `nimble search latex` and skim through the descriptions for something that sounds right |
08:09:46 | FromDiscord | <pk.kyle> ah, i forgot that command exists |
08:09:55 | FromDiscord | <pk.kyle> thx |
08:13:49 | FromDiscord | <Phil> Happy to help 😉 |
08:25:26 | * | junaid_ joined #nim |
08:46:36 | * | ntat quit (Quit: leaving) |
08:48:36 | FromDiscord | <Chronos [She/Her]> In reply to @ShalokShalom (ShalokShalom) "Why would it run": Because for stock JDKs it has to run in interpreted mode |
08:48:41 | FromDiscord | <Chronos [She/Her]> And that would be piss poor |
08:53:19 | FromDiscord | <Chronos [She/Her]> Also still means I have to recompile for every possible platform |
09:10:42 | FromDiscord | <vindaar> In reply to @pk.kyle "any quick and handy": Check out https://github.com/Vindaar/latexdsl↵also comes with a convenient compile command 👌 (depends on a local tex installation obviously, I'm not a madman) |
09:12:37 | FromDiscord | <pk.kyle> lol, thx! |
09:18:54 | FromDiscord | <vindaar> sent a code paste, see https://play.nim-lang.org/#ix=4GCe |
09:19:45 | FromDiscord | <vindaar> You can pass a `tmpl` argument to `compile` to replace the default template, defined here: https://github.com/Vindaar/LatexDSL/blob/master/src/latexdsl/latex_compiler.nim#L10-L20 |
09:25:30 | * | FromDiscord quit (Remote host closed the connection) |
09:25:43 | * | FromDiscord joined #nim |
09:49:01 | arkanoid | how can I get a longer list of trending packages in nimble.directory? |
10:28:09 | FromDiscord | <Phil> I don't think that query is paginated |
10:33:27 | * | PMunch joined #nim |
10:36:03 | * | blackbeard420 quit (Server closed connection) |
10:36:15 | * | blackbeard420 joined #nim |
10:36:39 | FromDiscord | <pk.kyle> In reply to @vindaar "By compile command, what": ok! |
10:36:50 | FromDiscord | <pk.kyle> (edit) "ok!" => "ok thx!" |
10:51:28 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4GCu |
10:51:51 | FromDiscord | <Phil> (edit) "https://play.nim-lang.org/#ix=4GCu" => "https://play.nim-lang.org/#ix=4GCv" |
10:52:07 | FromDiscord | <Phil> (edit) "https://play.nim-lang.org/#ix=4GCv" => "https://play.nim-lang.org/#ix=4GCw" |
10:55:39 | FromDiscord | <Phil> Actually I might be able to save myself the custom cstring type by just straight converting to string 🤔 |
10:55:39 | FromDiscord | <vindaar> I assume the `g_file_get_path` that returns `cstring` is a wrapped function from some library? In that case normally I would go with your approach, using the opportunity to have a nicer Nim like interface.↵However, given that distinct types are a pure Nim construct, I suppose you can just define the `importc` function to return your `distinct` type. That _should_ work I imagine, but I've never tried it |
10:56:10 | FromDiscord | <Phil> In reply to @vindaar "I assume the `g_file_get_path`": It is, this is for owlkettle, a gtk4 wrapper |
10:58:03 | FromDiscord | <vindaar> In reply to @vindaar "I assume the `g_file_get_path`": thinking about what I just said: I obviously have tried exactly that, haha. I define plenty of imported types by just doing a `distinct c<foo>`, which is pretty much identical |
10:58:55 | FromDiscord | <Phil> Check, so by using distinct type we can pretty easily distinguish between c-types whose memory we don't manage and c-types whose memory we do manage? |
11:01:09 | FromDiscord | <Phil> Now the more fundamental question.... err how do I free the memory of a cstring 😅 |
11:01:39 | FromDiscord | <Phil> So far I only ever had to reduce ref-counts by calling a proc from gtk since they were the ones freeing the memory |
11:01:55 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GCB |
11:02:24 | FromDiscord | <vindaar> If gtk4 hands you that cstring, doesn't its documentation tell you what you're supposed to do with it? Or does it just say "you're responsible to free it"? |
11:02:57 | FromDiscord | <Phil> In reply to @vindaar "If gtk4 hands you": The latter. I quote:https://docs.gtk.org/gio/method.File.get_path.html↵> The caller of the method takes ownership of the data, and is responsible for freeing it. |
11:04:37 | FromDiscord | <Phil> This is a nim-syntax question though right? I'm mostly asking because I see procs with dealloc prefixes, others with with "free" prefixes (though there's also a literal "free" proc without any docs) and I'm not sure what the path here is |
11:05:00 | FromDiscord | <odexine> In reply to @isofruit "The latter. I quote:https://docs.gtk.org/gio/method": doesnt mean they dont provide how to free it, just means that you have to put the code to free it yourself |
11:05:20 | FromDiscord | <odexine> In reply to @odexine "doesnt mean they dont": how to free it via a proc like g_whatever_free(ptr) |
11:07:17 | FromDiscord | <Phil> In reply to @odexine "doesnt mean they dont": I feel like if they did they'd have linked it |
11:07:22 | FromDiscord | <vindaar> either what Rika says or:↵the question is where does the `char ` come from then. If they `malloc` internally, then I guess you need to free manually yes. As I don't think you should use `dealloc` from Nim's stdlib (that should refer to Nim's allocator, which may not be `malloc` unless you use `-d:useMalloc`, you should best wrap `free` from `stdlib.h` |
11:08:16 | FromDiscord | <vindaar> sent a code paste, see https://play.nim-lang.org/#ix=4GCE |
11:10:11 | FromDiscord | <vindaar> (note that both of these will format your code and not return it verbatim like you print the `code` string there) |
11:10:34 | FromDiscord | <vindaar> sent a code paste, see https://play.nim-lang.org/#ix=4GCH |
11:10:57 | FromDiscord | <Phil> sent a long message, see http://ix.io/4GCI |
11:11:19 | FromDiscord | <Phil> In reply to @vindaar "either what Rika says": Does this imply that a memory allocated via allocator A must also be deallocated by allocator A and you can't do that via allocator B? |
11:11:37 | FromDiscord | <Phil> (edit) "B?" => "B?↵So allocators are not interoperable in that sense?" |
11:11:48 | FromDiscord | <vindaar> sent a code paste, see https://play.nim-lang.org/#ix=4GCJ |
11:11:52 | FromDiscord | <Phil> (edit) "In reply to @vindaar "either what Rika says": Does this imply that a ... memory" added "piece of" |
11:13:30 | FromDiscord | <vindaar> In reply to @isofruit "Does this imply that": Honestly, I never thought about that before, but it seems intuitively that it is not a good idea. The allocator knows which pointers it allocated, no? So if you use allocator B for buffer from A it seems like they would be out of sync and B wouldn't know about what is there to free? |
11:13:53 | FromDiscord | <Phil> Allocators "remember" the memory they allocated? |
11:13:55 | FromDiscord | <Phil> TIL |
11:14:11 | FromDiscord | <vindaar> How else would they know how much there is to free given a void pointer? |
11:14:14 | FromDiscord | <.aingel.> Say if I have a `var a: seq[ptr someObj]` and I want to pass this to a `proc foo(ctx: pointer)` , do I pass `foo (ref a)` or `foo (ptr a)` and what's the diff? |
11:14:31 | FromDiscord | <Phil> I thought it was a stateless operation in a sense, you ask for memory, they hand you some, notify everyone involved and then forget about it. Then you hand them the memory back, they analyze at runtime what they need to deallocate and then do so |
11:14:42 | FromDiscord | <vindaar> (I'm just assuming here, I'm not an allocator expert 🤣 ) |
11:15:22 | FromDiscord | <Phil> Wait, that has performance implications... I guess this kind of approach was used for better performance rather than having some kind of bit-pattern that denotes the edges of an allocation region |
11:15:27 | FromDiscord | <vindaar> maybe they pass it up one layer, that's possible. so the kernel keeps the info. But for a custom allocator? |
11:15:58 | FromDiscord | <vindaar> It's something to read up on I guess 😁 |
11:23:16 | FromDiscord | <ieltan> In reply to @.aingel. "Say if I have": I assume you're doing c interop but first of all are you sure you need `pointer` instead of `ptr T`? |
11:23:35 | FromDiscord | <.aingel.> yeah I need it as a void |
11:23:53 | FromDiscord | <.aingel.> Well, can I pass a non void pointer if the function wants it? |
11:24:36 | FromDiscord | <.aingel.> I keep getting now cannot cast to pointer |
11:25:08 | FromDiscord | <ieltan> I didn't mess around much with raw pointer I think you'll need to wait for someone more knowledgeable 😦 |
11:25:35 | FromDiscord | <.aingel.> Okie cool! |
11:25:49 | FromDiscord | <odexine> I don’t exactly understand your question |
11:25:59 | FromDiscord | <odexine> You want to turn a into a void pointer? |
11:26:20 | FromDiscord | <odexine> You can just cast |
11:26:23 | FromDiscord | <ieltan> You could do `pointer(a)` I think but I really don't guarantee any safeness |
11:26:28 | FromDiscord | <ieltan> Or cast |
11:26:51 | FromDiscord | <ieltan> I think you can type convert `ptr T` to `pointer` right? |
11:26:58 | FromDiscord | <odexine> Not sure |
11:27:00 | FromDiscord | <odexine> Never did |
11:28:28 | FromDiscord | <vindaar> @.aingel. the most important question first of all is what does the function actually want in terms of data. The entire buffer of all `ptr someObj`? |
11:28:40 | FromDiscord | <vindaar> In that case just do `cast[pointer](a[0].addr)` |
11:29:05 | FromDiscord | <.aingel.> In reply to @odexine "You can just cast": Not sure I follow that |
11:29:07 | FromDiscord | <.aingel.> What's a there |
11:29:12 | FromDiscord | <.aingel.> (edit) "a" => "`a`" |
11:29:38 | FromDiscord | <odexine> My bad. I misread |
11:29:42 | FromDiscord | <odexine> An element of a |
11:29:44 | FromDiscord | <.aingel.> No I want a pointer to a seq of someojbs |
11:29:46 | FromDiscord | <odexine> Is what I mean |
11:29:51 | FromDiscord | <odexine> Ah |
11:30:10 | FromDiscord | <.aingel.> (edit) "someojbs" => "someobjs" |
11:30:15 | FromDiscord | <odexine> You can’t make references without copies |
11:30:24 | FromDiscord | <odexine> So if you don’t mind then go with the pointer |
11:30:34 | FromDiscord | <.aingel.> In reply to @odexine "You can’t make references": What do you mean? |
11:30:37 | FromDiscord | <odexine> By taking the address of a then casting |
11:30:48 | FromDiscord | <.aingel.> What's the dif between ptr and ref? |
11:31:02 | FromDiscord | <odexine> You can make pointers to non-heap data |
11:31:05 | FromDiscord | <ieltan> Managed vs unmanaged pointer |
11:31:14 | FromDiscord | <ieltan> And above |
11:31:16 | FromDiscord | <odexine> References are always heap and if the data isn’t already in the heap it will be copied |
11:31:17 | FromDiscord | <.aingel.> In reply to @ieltan "Managed vs unmanaged pointer": Oh okay, that's what I thought |
11:31:34 | FromDiscord | <.aingel.> In reply to @odexine "References are always heap": Ptr can be to the stack? |
11:31:38 | FromDiscord | <ieltan> Yeah |
11:31:39 | FromDiscord | <odexine> Yes |
11:31:50 | FromDiscord | <.aingel.> Okie so if i don't care I can just use ptr |
11:31:55 | FromDiscord | <odexine> Sequences are in heap, but the semantics are as if they are not so it will still copy |
11:32:02 | FromDiscord | <.aingel.> Oh |
11:32:13 | FromDiscord | <odexine> In reply to @odexine "Sequences are in heap,": For references |
11:32:19 | FromDiscord | <ieltan> But that's why it's very unsafe since if the value goes out of scope the stack will pop it and the pointer becomes dangling |
11:32:20 | FromDiscord | <.aingel.> In reply to @odexine "Sequences are in heap,": It will make another copy? |
11:32:26 | FromDiscord | <odexine> If you use references yes |
11:32:27 | FromDiscord | <ieltan> Hope I got this right lol |
11:32:38 | FromDiscord | <.aingel.> In reply to @ieltan "But that's why it's": Hmmm |
11:32:40 | FromDiscord | <odexine> You did yes |
11:32:55 | FromDiscord | <.aingel.> In reply to @ieltan "But that's why it's": It won't deallocate the memory? |
11:33:19 | FromDiscord | <odexine> It will, but it might while you’re still using the data |
11:33:21 | FromDiscord | <ieltan> It will |
11:33:28 | FromDiscord | <.aingel.> Oh okay I think I get it |
11:33:47 | FromDiscord | <.aingel.> But okay, the main issue is that when I try to cast as pointer, I get `expected type` |
11:33:55 | FromDiscord | <odexine> So make sure the pointer is deleted or removed before you lose scope of the a variable |
11:34:12 | FromDiscord | <odexine> cast[pointer](addr a) |
11:34:17 | FromDiscord | <odexine> Is that what you did? |
11:34:32 | FromDiscord | <.aingel.> No I did ptr a |
11:34:45 | FromDiscord | <.aingel.> `cast[pointer](ptr a)` |
11:34:49 | FromDiscord | <odexine> That’s wrong |
11:34:57 | FromDiscord | <.aingel.> Why is it addr now |
11:35:03 | FromDiscord | <odexine> ptr is the type, addr is to get the pointer to a |
11:35:16 | FromDiscord | <.aingel.> Whats ref then |
11:35:18 | FromDiscord | <.aingel.> It's also a type? |
11:35:20 | FromDiscord | <odexine> Also a type |
11:35:29 | FromDiscord | <odexine> You get a ref in a different way |
11:35:39 | FromDiscord | <odexine> pointer is also a type |
11:35:51 | FromDiscord | <.aingel.> So the type determines whether it's managed or unmanaged |
11:35:56 | FromDiscord | <odexine> Its like the difference between and & in C |
11:36:16 | FromDiscord | <odexine> is a pointer (when on a type) |
11:36:31 | FromDiscord | <odexine> & gets you the pointer to the variable |
11:36:36 | FromDiscord | <odexine> (edit) "" => "\" |
11:36:59 | FromDiscord | <odexine> Same in Nim, ptr and addr |
11:37:08 | FromDiscord | <odexine> In reply to @.aingel. "So the type determines": Kinda |
11:37:20 | FromDiscord | <odexine> addr is strictly for pointers, it doesnt make refs |
11:37:35 | FromDiscord | <Phil> sent a long message, see http://ix.io/4GCO |
11:37:50 | FromDiscord | <Phil> (edit) "http://ix.io/4GCO" => "http://ix.io/4GCP" |
11:37:57 | FromDiscord | <odexine> In reply to @isofruit "I would like to": no |
11:38:08 | FromDiscord | <Phil> F.M.L. |
11:38:11 | FromDiscord | <odexine> If they do not specify then there is a documentation problem |
11:38:42 | FromDiscord | <_nenc> sent a code paste, see https://play.nim-lang.org/#ix=4GCQ |
11:39:08 | FromDiscord | <ieltan> The joy of C right |
11:39:48 | FromDiscord | <odexine> In reply to @ieltan "The joy of C": IKR |
11:40:22 | FromDiscord | <Phil> I don't know why people do this to themselves, I can only assume C-programmers are a cult of masochists |
11:40:41 | FromDiscord | <odexine> More, insane people |
11:41:00 | FromDiscord | <.aingel.> ` var nodes = (cast[ptr seq[string]](ctx))[]` |
11:41:15 | FromDiscord | <Phil> Without knowing that this is for, this looks cursed as hell |
11:41:16 | FromDiscord | <.aingel.> Is this the right way of deref my void pointer? |
11:41:19 | FromDiscord | <odexine> In reply to @.aingel. "` var nodes": That looks sketchy as fuck |
11:41:28 | FromDiscord | <ieltan> Oh my. God |
11:41:32 | FromDiscord | <odexine> Why is it suddenly a string |
11:41:37 | FromDiscord | <.aingel.> How do I deref my pointer |
11:41:44 | FromDiscord | <.aingel.> I want a seq of strings just to make it simple |
11:41:55 | FromDiscord | <.aingel.> So I want to pass a seq[string] to a c void arg |
11:41:57 | FromDiscord | <ieltan> Don't cast it to `string`, make it a `cstring` at least |
11:41:58 | FromDiscord | <.aingel.> and then use it there |
11:42:09 | FromDiscord | <Phil> Aingel immediately causing people to dogpile 😄 |
11:42:11 | FromDiscord | <.aingel.> Why would I have to use cstring |
11:42:13 | FromDiscord | <ieltan> But then again that's not the biggest issue, what are you trying to accomplish |
11:42:22 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GCW |
11:42:33 | FromDiscord | <ieltan> `string` is Nim's own managed string type |
11:42:43 | FromDiscord | <.aingel.> Yeah I want to use that |
11:42:46 | FromDiscord | <.aingel.> I want to use nim types |
11:42:49 | FromDiscord | <.aingel.> In my wrapped function |
11:43:17 | FromDiscord | <.aingel.> I'm just passing a void pointer I don't have to use c types for this afaik |
11:43:46 | FromDiscord | <vindaar> In reply to @heysokam "that makes `codeRT` just": Sorry, you need to be more clear about what you actually want. I thought you wanted a string representation of your code. |
11:43:50 | FromDiscord | <vindaar> Anyway I'll be away in 5 min |
11:43:54 | FromDiscord | <odexine> @Phil seems like it’s all green for you to use the free function you found https://docs.gtk.org/gtk4/question_index.html |
11:43:59 | FromDiscord | <ieltan> In reply to @.aingel. "I want to use": I don't think it's really trivial |
11:44:00 | FromDiscord | <sOkam! 🫐> In reply to @vindaar "Sorry, you need to": yes i do, but then I want to read it back too |
11:44:03 | FromDiscord | <odexine> See “memory management” portion |
11:44:11 | FromDiscord | <vindaar> In reply to @heysokam "yes i do, but": why would you want that? |
11:44:11 | FromDiscord | <ieltan> Let me look this up |
11:44:28 | FromDiscord | <sOkam! 🫐> In reply to @vindaar "why would you want": because of development testing an ast interpreter |
11:44:33 | FromDiscord | <.aingel.> In reply to @ieltan "Let me look this": That doesn't make sense to me then |
11:44:40 | FromDiscord | <Phil> In reply to @odexine "<@180601887916163073> seems like it’s": Oh thank god |
11:44:41 | FromDiscord | <sOkam! 🫐> i want to have symbols, but also string-to-ast |
11:44:42 | FromDiscord | <demotomohiro> In reply to @.aingel. "` var nodes": It probably correct as long as ctx points to vaild `seq[string]`. |
11:44:50 | FromDiscord | <Phil> I was on my third SO question by now |
11:45:19 | FromDiscord | <.aingel.> In reply to @demotomohiro "It probably correct as": Yeah, well I am getting ctx as addr seq[string] |
11:45:30 | FromDiscord | <vindaar> In reply to @heysokam "because of development testing": Then just use the AST directly from the macro? I don't quite understand. |
11:45:41 | FromDiscord | <.aingel.> `var a: seq[string]`↵`ctx = addr a` |
11:45:50 | FromDiscord | <sOkam! 🫐> In reply to @vindaar "Then just use the": the ast from the macro gives you a symbol `NimNode` not a `procdef` |
11:46:01 | FromDiscord | <.aingel.> (edit) "addr a`" => "cast[pointer](addr a)`" |
11:46:03 | FromDiscord | <sOkam! 🫐> (edit) "`procdef`" => "`nnkProcDef` as it should" |
11:46:08 | FromDiscord | <odexine> In reply to @isofruit "I was on my": Literally searched "gtk4 string free" though |
11:46:14 | FromDiscord | <.aingel.> @demotomohiro Does that make sense? |
11:46:17 | FromDiscord | <sOkam! 🫐> (edit) "In reply to @vindaar "Then just use the": the ast from the macro gives you a ... symbol" added "`nnkSymbol`" |
11:46:19 | FromDiscord | <vindaar> In reply to @heysokam "the ast from the": you need to use `getImpl` and friends on the symbol to get the implementation |
11:46:37 | FromDiscord | <sOkam! 🫐> In reply to @vindaar "you need to use": but getImpl doesn't work on that astToStr node |
11:46:57 | FromDiscord | <.aingel.> It sort of works, like it compiles and runs, but it doesn't seem to "keep" the memory |
11:47:11 | FromDiscord | <.aingel.> That function runs multiple times but it's like the seq gets reset each time |
11:47:44 | FromDiscord | <vindaar> In reply to @heysokam "but getImpl doesn't work": `astToStr` returns a string. You mean after using `parseExpr` on _that_ string? |
11:47:46 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GD1 |
11:48:03 | FromDiscord | <sOkam! 🫐> In reply to @vindaar "`astToStr` returns a string.": yeah |
11:48:32 | FromDiscord | <demotomohiro> In reply to @.aingel. "<@288750616510201856> Does that make": Yes. But you have to make sure that it variable `a` still exists on stack when dereference. |
11:48:42 | FromDiscord | <Phil> In reply to @odexine "Literally searched "gtk4 string": I bow to your google fu then, you got me this time |
11:48:55 | FromDiscord | <Phil> Maybe formulating it as a question was not the smartest move |
11:49:06 | FromDiscord | <.aingel.> In reply to @demotomohiro "Yes. But you have": Yeah it does still exist |
11:49:28 | FromDiscord | <vindaar> sent a code paste, see https://play.nim-lang.org/#ix=4GD2 |
11:49:32 | FromDiscord | <.aingel.> sent a code paste, see https://play.nim-lang.org/#ix=4GD3 |
11:50:20 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GD4 |
11:50:26 | FromDiscord | <sOkam! 🫐> its returning something else |
11:50:45 | FromDiscord | <vindaar> sorry, ping me with your entire code and I'll look at it later |
11:51:19 | * | derpydoo quit (Ping timeout: 264 seconds) |
11:52:08 | FromDiscord | <ieltan> In reply to @.aingel. "That function runs multiple": My guess is that `seq` is destroyed everytime the function finishes (Nim has RAII) so you'll need something else that isn't destroyed |
11:52:41 | FromDiscord | <ieltan> Something like `uncheckedArray[string]` would maybe do the job? |
11:53:22 | FromDiscord | <ieltan> Also still not sure how to convert a `cstring` to `string` apart from casting |
11:53:41 | FromDiscord | <.aingel.> In reply to @ieltan "Also still not sure": That is not an issue |
11:53:53 | FromDiscord | <.aingel.> Idk why you think that's an issue thoguh |
11:54:03 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GD6 |
11:55:25 | FromDiscord | <.aingel.> In reply to @.aingel. "Idk why you think": Oh maybe it is an issue for uncheckedarray |
11:55:29 | FromDiscord | <.aingel.> (edit) "uncheckedarray" => "UncheckedArray" |
11:56:46 | FromDiscord | <.aingel.> I can't assign an uncheckedarray to a var |
11:58:44 | FromDiscord | <toma400> sent a code paste, see https://play.nim-lang.org/#ix=4GDb |
11:58:56 | FromDiscord | <demotomohiro> In reply to @.aingel. "That function runs multiple": If seq was declared in proc as local variable, it is freed when exit the proc and recreated when the proc called again. |
11:59:15 | FromDiscord | <ieltan> In reply to @.aingel. "I can't assign an": Eh.. My bad, it should be `ptr uncheckedArray[string]` I think |
12:02:08 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4GDd |
12:04:14 | FromDiscord | <_gumbercules> cstrings are just pointers |
12:04:21 | FromDiscord | <demotomohiro> In reply to @isofruit "Could I get a": Doesnt your `=copy` copy content of source string to dest? |
12:04:21 | FromDiscord | <_gumbercules> you shouldn't need to destroy them |
12:04:23 | FromDiscord | <sOkam! 🫐> In reply to @toma400 "I still can't get": `category name kind output` -> `var thing :MyType= 42`↵`:` is noise that belongs to the kind↵ They are indicators of properties of the kind and have nothing to do with the name↵I'm just the only weirdo that thinks this way, and as such not understood here at all. But it does make a lot of sense |
12:04:50 | FromDiscord | <Phil> In reply to @_gumbercules "you shouldn't need to": They come from gtk which instructs me that I need to take care of freeing that memory |
12:04:59 | FromDiscord | <Phil> So I do via destroy hook |
12:05:19 | FromDiscord | <_gumbercules> okay I guess if that's what GTK is telling you to do... |
12:05:33 | FromDiscord | <_gumbercules> but yeah @demotomohiro has a good point re> your copy |
12:05:38 | FromDiscord | <_gumbercules> your not actually copying anything |
12:05:44 | FromDiscord | <_gumbercules> you're just copying the pointers |
12:05:47 | FromDiscord | <Phil> In reply to @demotomohiro "Doesnt your `=copy` copy": It should copy the contents... which I guess it doesn't, right, copying refs |
12:05:59 | FromDiscord | <Phil> ` dest[] = source[]` I think? |
12:06:01 | FromDiscord | <_gumbercules> you need to know the size of the memory you want to copy |
12:06:19 | FromDiscord | <_gumbercules> I don't think that will work - I think you need `copyMem` |
12:06:35 | FromDiscord | <_gumbercules> and again the number of bytes to copy |
12:06:41 | FromDiscord | <demotomohiro> In reply to @isofruit "Could I get a": if I understand correctly, if you dont copy content of string in `=copy`, it might cause free after use. |
12:07:09 | FromDiscord | <_gumbercules> try `dest[] = source[]` but I don't think th at will work - maybe |
12:07:23 | FromDiscord | <_gumbercules> (edit) "th at" => "that" |
12:07:37 | FromDiscord | <Phil> sent a long message, see http://ix.io/4GDe |
12:08:19 | FromDiscord | <_gumbercules> I wouldn't do this this way then |
12:08:25 | FromDiscord | <_gumbercules> I'd wrap `g_free` |
12:08:32 | FromDiscord | <_gumbercules> and just use `cstring` instead of a `distinct cstring` |
12:08:52 | FromDiscord | <_gumbercules> if you want to wrap another type around the GTK type that calls `g_free` for you that's fine |
12:08:59 | FromDiscord | <Phil> In reply to @_gumbercules "and just use `cstring`": That I don't wanna do because I don't want to do this to all cstrings, there are a couple functions that return cstring where you don't free |
12:09:23 | FromDiscord | <_gumbercules> mmm |
12:10:02 | FromDiscord | <_gumbercules> well give what you have a shot and see what happens |
12:10:12 | FromDiscord | <_gumbercules> and add the `dest[] = src[]` bit |
12:10:21 | FromDiscord | <_gumbercules> worst that can happen is you will segfault and then figure out what to do |
12:10:32 | FromDiscord | <Phil> In reply to @demotomohiro "if I understand correctly,": That is correct, I'll see what else I can do here |
12:10:39 | FromDiscord | <Phil> Okay, time to see what blows up on me |
12:10:58 | FromDiscord | <Phil> Or rather adjust all the procs that give me cstring to give me GtkString instead |
12:11:00 | FromDiscord | <_gumbercules> if you don't pass these strings back and forth between Nim and GTK you might be okay |
12:11:05 | FromDiscord | <Phil> or I guess "OwnedGtkString" or sth |
12:11:21 | FromDiscord | <.aingel.> In reply to @demotomohiro "If seq was declared": I'm not trying to create it though, just deref the pointer |
12:11:25 | FromDiscord | <_gumbercules> if you do - I'm guessing you'll run into issues with Nim's gc trying to destroy something that is still referenced on the C side or vis versa |
12:11:39 | FromDiscord | <.aingel.> How can I access it via dereffing it without getting the gc to act on it |
12:12:19 | FromDiscord | <sOkam! 🫐> Is it not possible to get a `nnkSym` from `astToStr( myProc ).parseExpr()`?↵I'm getting a `nnkIdent` but I need a symbol for `getImpl`↵Is it possible to do this in some way? |
12:14:07 | * | jmdaemon quit (Ping timeout: 244 seconds) |
12:14:59 | FromDiscord | <_gumbercules> In reply to @.aingel. "How can I access": if you don't want the GC to manage the memory behind the seq then manually allocate the memory yourself and dispose of it yourself |
12:15:14 | FromDiscord | <.aingel.> In reply to @_gumbercules "if you don't want": I don't mind the GC managing it when I create it |
12:15:31 | FromDiscord | <_gumbercules> the GC isn't doing anything when you deref and access the value |
12:15:33 | FromDiscord | <.aingel.> So I create it in one proc, then pass the addr to a second proc |
12:15:34 | FromDiscord | <sirolaf> In reply to @heysokam "Is it not possible": https://nim-lang.org/docs/macros.html#bindSym%2C%2CBindSymRule |
12:15:41 | FromDiscord | <.aingel.> In reply to @_gumbercules "the GC isn't doing": Thats what i would think to |
12:15:42 | FromDiscord | <_gumbercules> right but as soon as that first proc ends |
12:16:02 | FromDiscord | <.aingel.> In reply to @_gumbercules "right but as soon": It ends only after the callbacks have been called |
12:16:18 | FromDiscord | <.aingel.> sent a code paste, see https://play.nim-lang.org/#ix=4GD3 |
12:16:27 | * | junaid_ quit (Remote host closed the connection) |
12:16:28 | FromDiscord | <_gumbercules> hold on |
12:16:45 | FromDiscord | <.aingel.> So the callbacks triggered by lxb_selectors_find call , and then print nodes gets called |
12:16:46 | FromDiscord | <_gumbercules> you're passing a reference via `cast[pointer](addr nodes)` and the GC isn't aaware you're doing this |
12:16:58 | FromDiscord | <.aingel.> Thats cool I dont want it to know |
12:17:06 | FromDiscord | <_gumbercules> okay so think about it then |
12:17:14 | FromDiscord | <_gumbercules> the GC doesn't know you've essentially created a ref |
12:17:18 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4GDg |
12:17:22 | FromDiscord | <_gumbercules> at the end of the first proc |
12:17:31 | FromDiscord | <.aingel.> Whats the first proc |
12:17:35 | FromDiscord | <.aingel.> The calling proc right |
12:17:38 | FromDiscord | <_gumbercules> the proc where you declare the sequence |
12:17:39 | FromDiscord | <Phil> That is inim, no hook defined |
12:17:43 | FromDiscord | <.aingel.> Sure |
12:17:51 | FromDiscord | <_gumbercules> it's' going to say - okay this sequence isn't referenced anymore anywhere - I should destroy it |
12:17:59 | FromDiscord | <_gumbercules> because the GC doesn't know you passed an unsafe ref around somewhere |
12:18:03 | FromDiscord | <.aingel.> But the second proc has already been called |
12:18:31 | FromDiscord | <_gumbercules> I don't know what the second procedure is doing with that sequence |
12:18:40 | FromDiscord | <_gumbercules> so I can't really say what the code you're calling into is doing with it |
12:18:43 | FromDiscord | <.aingel.> Doesnt mater though it's already called it |
12:18:46 | FromDiscord | <_gumbercules> yes it does |
12:19:00 | FromDiscord | <_gumbercules> because if it takes that reference and then passes it around or stores it and tries to access it later |
12:19:03 | FromDiscord | <_gumbercules> and the memory has been collected |
12:19:05 | FromDiscord | <.aingel.> Thats fine |
12:19:09 | FromDiscord | <.aingel.> Thats not happening though |
12:19:13 | FromDiscord | <_gumbercules> what is the problem then? |
12:19:32 | FromDiscord | <.aingel.> I'm saying the order of operation is proc1 call starts, proc 2 gets called three times or so, then proc1 ends |
12:19:38 | FromDiscord | <.aingel.> So the order of operation is fine |
12:19:47 | FromDiscord | <_gumbercules> thats' not really how CPUs work but regardless, what is the problem |
12:20:14 | FromDiscord | <_gumbercules> in terms of stack frames sure in terms of what instructions get executed in what order, there's no guarantee there |
12:20:34 | FromDiscord | <.aingel.> Yeah well at least in terms of stack frames |
12:20:43 | FromDiscord | <.aingel.> I mean idk if anything more than that is really relevant to this |
12:20:49 | FromDiscord | <_gumbercules> what's the problem though lol |
12:21:01 | FromDiscord | <_gumbercules> I'm stil unclear about that |
12:21:19 | FromDiscord | <.aingel.> The issue is that within proc2 when I deref the pointer it always has nothing in it |
12:21:29 | FromDiscord | <.aingel.> Even thoguh I add to it and proc2 gets called mulitple times before proc1 ends |
12:22:08 | FromDiscord | <_gumbercules> I'm trying to find the original code / message |
12:22:12 | FromDiscord | <.aingel.> sent a code paste, see https://play.nim-lang.org/#ix=4GDh |
12:22:15 | FromDiscord | <.aingel.> Thats my proc2 |
12:22:19 | FromDiscord | <_gumbercules> sent a code paste, see https://play.nim-lang.org/#ix=4GD3 |
12:22:21 | FromDiscord | <_gumbercules> okay |
12:22:30 | FromDiscord | <.aingel.> My proc2 is the callback basically |
12:22:36 | FromDiscord | <.aingel.> triggered by selectors_find |
12:22:41 | FromDiscord | <_gumbercules> so `lxb_selectors_find` is supposed to populate the sequence? |
12:22:43 | FromDiscord | <.aingel.> Each time I print nodes it's just meow |
12:22:49 | FromDiscord | <.aingel.> In reply to @_gumbercules "so `lxb_selectors_find` is supposed": Yeah |
12:22:59 | FromDiscord | <.aingel.> If I increment a global var and print it |
12:23:00 | FromDiscord | <_gumbercules> what does `findcb` do? |
12:23:02 | FromDiscord | <.aingel.> It increments |
12:23:09 | FromDiscord | <.aingel.> It gets triggere |
12:23:11 | FromDiscord | <.aingel.> (edit) "triggere" => "triggered" |
12:23:18 | FromDiscord | <.aingel.> It's a callback for that selector function |
12:23:23 | * | junaid_ joined #nim |
12:23:27 | FromDiscord | <.aingel.> So actually selectors find doesnt populate it, its findcd |
12:23:29 | FromDiscord | <.aingel.> (edit) "findcd" => "findcb" |
12:23:35 | FromDiscord | <_gumbercules> no I get that but can you paste its implementation? |
12:23:38 | FromDiscord | <.aingel.> But selectors_find triggers findcb |
12:23:42 | FromDiscord | <.aingel.> No i cant its a c func |
12:24:03 | FromDiscord | <_gumbercules> yeah there's too much interop going on here to really reason about what's wrong with your code |
12:24:05 | FromDiscord | <sOkam! 🫐> In reply to @sirolaf "https://nim-lang.org/docs/macros.html#bindSym%2C%2C": I'm getting `string literal expected` now when doing `strCode.parseExpr().bindSym()` |
12:24:18 | FromDiscord | <.aingel.> I dont think it really matters though |
12:24:21 | FromDiscord | <_gumbercules> I'd need to see some C code as well |
12:24:22 | FromDiscord | <_gumbercules> it does |
12:24:32 | FromDiscord | <.aingel.> Okay if u say so |
12:24:40 | FromDiscord | <_gumbercules> because obviously it's not working and the Nim code you've shown isn't enough to understand the root cause of the issue |
12:25:15 | FromDiscord | <_gumbercules> without seeing `find_cb` and `lxb_selectors_find` it's gong to be difficult for anyone to reason about why your code isn't doing what you expect it to do |
12:26:02 | FromDiscord | <_gumbercules> if you don't want to share that code or can't for whatever reason, you should probably lean on address sanitizer or Valgrind |
12:26:32 | FromDiscord | <.aingel.> Idk |
12:27:01 | FromDiscord | <.aingel.> I feel like you're jumping instantly to there being something going on in the c code |
12:27:34 | FromDiscord | <_gumbercules> I'm not jumping anywhere but you've shared 3 lines of Nim code that are doing interop with C - how you expect anyone to troubleshoot an issue when you've shared three lines of code that call into who knows what other code is beyond me |
12:27:43 | FromDiscord | <.aingel.> Just assume that its just passing the pointer |
12:27:54 | FromDiscord | <.aingel.> And not doing anything weird with it |
12:28:05 | FromDiscord | <ieltan> I don't think the casting here is sane anyways with the pointer being represented as a `ptr seq[string]` it probably does not do what you want |
12:28:07 | FromDiscord | <.aingel.> This is a widely used library I am pretty sure it's just passing the ctx pointer |
12:28:28 | FromDiscord | <.aingel.> In reply to @ieltan "I don't think the": Can u explain pls |
12:28:34 | FromDiscord | <_gumbercules> Nim strings are not C strings |
12:29:15 | FromDiscord | <.aingel.> Okay and |
12:29:27 | FromDiscord | <.aingel.> I just want to pass a generic pointer |
12:29:56 | FromDiscord | <ieltan> In reply to @.aingel. "Can u explain pls": Because `string` is a complex object, merely casting a pointer to it doesn't mean it will just "work" |
12:29:57 | FromDiscord | <_gumbercules> that's not the point |
12:30:05 | FromDiscord | <_gumbercules> you're passing a pointer to a sequence of Nim strings |
12:30:17 | FromDiscord | <_gumbercules> and then you're apparently creating Nim strings in your C code and populating that sequence with them? |
12:30:22 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GDj |
12:30:23 | FromDiscord | <_gumbercules> that's not going to work.... |
12:30:26 | FromDiscord | <.aingel.> In reply to @_gumbercules "and then you're apparently": No i am not |
12:30:29 | FromDiscord | <sOkam! 🫐> so if you are mapping regular C, that is going to fail |
12:30:30 | FromDiscord | <.aingel.> It's all nim code |
12:30:43 | FromDiscord | <ieltan> In reply to @heysokam "<@1152336447467163790> I don't know": Yeah I've been looking for this code snippet lol |
12:30:45 | FromDiscord | <_gumbercules> you said earlier that your callback was written in C |
12:30:51 | FromDiscord | <.aingel.> No |
12:30:58 | FromDiscord | <.aingel.> The function that triggers the callback is in c |
12:31:02 | FromDiscord | <.aingel.> But the callback is in nim |
12:31:10 | FromDiscord | <sOkam! 🫐> In reply to @ieltan "Yeah I've been looking": https://nim-lang.org/docs/destructors.html |
12:31:15 | FromDiscord | <_gumbercules> okay well - again it's going to be difficult for me to debug this with only seeing three lines of code |
12:31:21 | FromDiscord | <_gumbercules> my baby is awawke and crying so I gotta go get him |
12:31:29 | FromDiscord | <.aingel.> okay thanks for the help! |
12:31:34 | FromDiscord | <sOkam! 🫐> In reply to @.aingel. "But the callback is": then why are you casting at all?↵casting is the most unsafe thing you can do in nim |
12:31:42 | FromDiscord | <sOkam! 🫐> if the data is from nim, don't cast |
12:31:44 | FromDiscord | <sOkam! 🫐> convert it |
12:32:02 | FromDiscord | <sOkam! 🫐> even if the data is from C you should convert it in a proc, not cast it |
12:32:16 | FromDiscord | <.aingel.> Because the callback is triggered through C |
12:32:20 | FromDiscord | <.aingel.> and it takes a void pointer |
12:32:27 | FromDiscord | <.aingel.> But the callback implementation is in nim |
12:32:35 | FromDiscord | <sOkam! 🫐> so you are sending a ptr seq to C? |
12:32:39 | FromDiscord | <.aingel.> Yes |
12:32:44 | FromDiscord | <.aingel.> And it calls a callback which is in nim |
12:32:51 | FromDiscord | <.aingel.> Which takes a `pointer` |
12:32:55 | FromDiscord | <.aingel.> As the argument |
12:33:12 | FromDiscord | <.aingel.> Thats why I need to cast it |
12:33:25 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GDk |
12:33:42 | FromDiscord | <sOkam! 🫐> In reply to @.aingel. "Which takes a `pointer`": any pointer in nim is compatible with `pointer`. you dont need to cast them |
12:33:43 | FromDiscord | <ieltan> Does C even understand what a `seq` is? you would have to send it an `uncheckedArray` if it doesn't |
12:33:54 | FromDiscord | <.aingel.> I dont even want this to be a seq[string] eventually, I'm just using this as a placeholder for now |
12:33:55 | FromDiscord | <ieltan> ptr |
12:34:01 | FromDiscord | <sOkam! 🫐> In reply to @ieltan "Does C even ": it doesn't, and all you need to send is a ptr to the first entry of the data |
12:34:02 | FromDiscord | <.aingel.> I want it to be a seq of some other generic type |
12:34:31 | FromDiscord | <.aingel.> In reply to @heysokam "any pointer in nim": Okay that helps |
12:34:48 | FromDiscord | <sOkam! 🫐> also, you need to convert to `cstringArray` before sending to C, otherwise if its a nim string it wont work |
12:34:55 | FromDiscord | <.aingel.> But still have the problem of when I deref it seems to be empty everytime |
12:35:01 | FromDiscord | <ieltan> Ok, first of all, you need to make this work at a low level and then make a high level interface so that users don't have to work with unsafe data |
12:35:07 | FromDiscord | <.aingel.> In reply to @heysokam "also, you need to": I dont even want this to be a string |
12:35:27 | FromDiscord | <ieltan> If you don't make it work at a low level first then don't bother trying to pass seqs and strings and whatnot |
12:35:51 | FromDiscord | <sOkam! 🫐> In reply to @.aingel. "I dont even want": I'm missing some context:↵1. whats your input?↵2. whats your output?↵3. whats the shape of the C function you are sending your data to? |
12:37:30 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4GDm |
12:38:08 | FromDiscord | <ieltan> So much C interoopin today 🤔 |
12:39:52 | FromDiscord | <Phil> The fact that I'm part of the C interoopin crew is still mildly nuts to me |
12:42:09 | FromDiscord | <_gumbercules> I'm back |
12:42:19 | FromDiscord | <_gumbercules> In reply to @ieltan "So much C interoopin": this is most of my code |
12:49:28 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4GDq |
12:49:44 | FromDiscord | <_gumbercules> In reply to @isofruit "Okay I got further": yeah I got to the `.pop` thing just now |
12:50:14 | FromDiscord | <Phil> I mean the examples compile without the copy hook and the one app-example in owlkettle where I can test it works fine |
12:50:24 | FromDiscord | <_gumbercules> looking |
12:50:25 | FromDiscord | <Phil> I put an echo in the destroy hook and it gets called as it shoul |
12:50:26 | FromDiscord | <Phil> (edit) "shoul" => "should" |
12:51:02 | FromDiscord | <Phil> I'm tempted to ask #internals if this is a compiler bug |
12:52:08 | FromDiscord | <Phil> Because the error disappears if:↵A) You don't use {.pop.} or↵B) You don't have a destroy hook or↵C) You don't have a copy hook (well that one is self-explanatory) |
12:52:24 | FromDiscord | <Phil> It makes no sense that the combo of {.pop.} with a destroy hook somehow leads to the creation of a copyhook |
12:54:45 | FromDiscord | <_gumbercules> maybe? |
12:54:47 | FromDiscord | <_gumbercules> sent a code paste, see https://play.nim-lang.org/#ix=4GDs |
12:55:20 | FromDiscord | <_gumbercules> I think what was leading to the creation of the copy hook was the conversion of your distinct type back to `cstring` and `pointer` |
12:55:55 | FromDiscord | <_gumbercules> I guess the copy hook from cstring gets included in the C code to perform the conversion |
12:59:01 | FromDiscord | <Phil> Is there a way where I don't tie g_free to OwnedGtkString? There may be other calls to g_free with other types in the future |
12:59:50 | FromDiscord | <Phil> Well, I guess I can just leave out the copy, if it basically uses the cstring copy hook I'm fine |
13:26:01 | * | blackbeard420 quit (Quit: ZNC 1.8.2 - https://znc.in) |
13:26:14 | * | blackbeard420 joined #nim |
13:41:42 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GDH |
13:57:05 | * | ntat joined #nim |
14:19:31 | FromDiscord | <vindaar> sent a code paste, see https://play.nim-lang.org/#ix=4GDR |
15:24:56 | * | ntat quit (Quit: leaving) |
15:25:42 | * | krux02 joined #nim |
15:30:24 | FromDiscord | <sOkam! 🫐> sent a code paste, see https://play.nim-lang.org/#ix=4GEk |
15:35:00 | FromDiscord | <odexine> youre pretty much asking for the whole compiler's source at that point you know |
15:35:15 | FromDiscord | <odexine> what else is a compiler other than something that reads files and then generates something out of it |
15:35:34 | FromDiscord | <odexine> can you specify more about what you're aiming for |
15:48:55 | FromDiscord | <sOkam! 🫐> In reply to @odexine "can you specify more": Writing a compiler for nim code, that generates different code than C |
15:49:12 | FromDiscord | <sOkam! 🫐> there is probably a better explanation for that, using more compiler-correct terms, but that's my goal |
15:50:04 | FromDiscord | <sOkam! 🫐> You can think of it, in simpler terms, like what `treeform/shady` does, but at runtime with the compiler as a library... not at compiletime through macros/metaprogramming |
15:51:17 | FromDiscord | <sOkam! 🫐> In reply to @odexine "youre pretty much asking": Yeah I understand. That's basically the goal↵I just want to get the AST that the compiler itself is using to codegen, but do something with it in a different way than what the nimc codegen section does |
15:53:28 | FromDiscord | <Phil> Curiosity question: is it basically mandatory in c libs to provide functions that can free all the various data your lib provides? |
15:54:02 | FromDiscord | <odexine> In reply to @isofruit "Curiosity question: is it": yes |
15:54:26 | FromDiscord | <odexine> allocate and deallocate (malloc and free) are bound to the allocator |
15:54:45 | FromDiscord | <odexine> if you allocate memory with one allocator and deallocate it with another allocator then 💥 |
15:55:51 | FromDiscord | <Phil> Does every program provide its own instance of an allocator? |
15:57:11 | FromDiscord | <Chronos [She/Her]> In reply to @heysokam "Writing a compiler for": Pass `--path:"$nim"` to the compiler, and make sure you define `nimcore`, but you'll suffer immensely :p |
15:57:11 | FromDiscord | <odexine> no, most programs usually just use regular malloc/free |
15:57:30 | FromDiscord | <Chronos [She/Her]> Using compiler libraries after that is just `import compiler/insertLibraryHere` |
15:57:38 | FromDiscord | <Chronos [She/Her]> You will suffer |
15:57:40 | FromDiscord | <Phil> And "regular malloc/free" is provided by the os? |
15:57:54 | FromDiscord | <odexine> either that or a dynamic library |
15:58:04 | FromDiscord | <odexine> this can also be overridden |
15:58:21 | FromDiscord | <Chronos [She/Her]> In reply to @chronos.vitaqua "You ***will*** suffer": Look at compiler/jsgen.nim |
15:59:00 | FromDiscord | <Phil> So there an allocator comes from is kind of wild west: there's a standard and a lot of things follow it but enough variance that you can never rely on that |
15:59:05 | FromDiscord | <sOkam! 🫐> In reply to @chronos.vitaqua "You ***will*** suffer": I cannot, if I don't know how to read the file into an AST |
15:59:07 | FromDiscord | <Phil> (edit) "there" => "where" |
16:01:57 | FromDiscord | <sOkam! 🫐> I've been reading the ast/parser/etc files... but all of those are used on already existing data that is coming from somewhere↵My question is how to find where that somewhere comes from, since the files must be read somewhere by the compiler |
16:01:59 | FromDiscord | <odexine> In reply to @isofruit "So where an allocator": basically the rule is: allocation functions pair with free functions. if you're using malloc/free, no problem in any case |
16:02:18 | FromDiscord | <odexine> if you're using a custom allocator then they should be paired too ofc |
16:03:00 | FromDiscord | <Chronos [She/Her]> In reply to @heysokam "I've been reading the": Should come from somewhere in main.nim or nim.nim in the compiler folder |
16:03:19 | FromDiscord | <sOkam! 🫐> yeah but main is huge |
16:05:12 | FromDiscord | <Chronos [She/Her]> I mean... If you want to do what you want, gotta do the effort :p |
16:06:44 | * | xaltsc quit (Ping timeout: 245 seconds) |
16:08:16 | FromDiscord | <sOkam! 🫐> In reply to @chronos.vitaqua "I mean... If you": I think the issue is that the data for main is not coming from main, its coming from nim.nim |
16:08:28 | FromDiscord | <sOkam! 🫐> that's what was throwing me off |
16:09:16 | FromDiscord | <sOkam! 🫐> the file seems to be read into a ModuleGraph object, and that happens at nim.nim and sent to main |
16:53:12 | * | rockcavera joined #nim |
16:53:43 | * | def- quit (Quit: -) |
16:54:11 | FromDiscord | <sOkam! 🫐> I think I found it by reading the nimpretty section↵They key seems to be in `parseAll()`. That function returns a PNode, which seems to be the root of the AST ✍️↵So its all a matter of reading the file into a parser object (haven't figured out how) and then use the resulting PNode |
16:54:27 | * | def- joined #nim |
17:03:41 | * | junaid_ quit (Remote host closed the connection) |
17:06:23 | FromDiscord | <.aingel.> okay so my code works if I do ↵` (cast[ptr seq[string]](ctx))[].add("meow")` ↵but not if I do |
17:06:40 | FromDiscord | <.aingel.> ` var foo = (cast[ptr seq[string]](ctx))[]`↵` foo.add("meow")` |
17:06:47 | FromDiscord | <.aingel.> Basically when I put it to a var, it seems to create a copy of it |
17:06:57 | FromDiscord | <.aingel.> Instead of just working with the data in the pointer |
17:06:59 | FromDiscord | <Elegantbeef> Strings are value types so, yes |
17:07:07 | FromDiscord | <.aingel.> It's not a string though |
17:07:13 | FromDiscord | <Elegantbeef> well seqs and strings |
17:07:21 | FromDiscord | <.aingel.> But it works if I don't assign to var |
17:07:27 | FromDiscord | <Elegantbeef> remove the dereference and move it to `foo[].add` |
17:07:45 | FromDiscord | <.aingel.> Oh I see |
17:07:48 | FromDiscord | <.aingel.> Yeah that makes sense |
17:08:09 | FromDiscord | <Elegantbeef> Yes cause dereferencing creates an L-value |
17:08:27 | FromDiscord | <.aingel.> Gotcha |
17:08:32 | FromDiscord | <.aingel.> Yeah your way works great |
17:08:37 | FromDiscord | <sOkam! 🫐> actually, nvm. its not `parseAll` its `parseString`!! Literally what I needed 🥳 |
17:08:39 | FromDiscord | <.aingel.> What's an L-value? |
17:08:50 | FromDiscord | <Elegantbeef> In the single line the `[]` emits `var seq[string]` in the later way you copy the seq due to storing to a variable |
17:09:09 | FromDiscord | <Elegantbeef> It's a C++ term, `L-Value` practically means a writeable expression |
17:09:15 | FromDiscord | <.aingel.> Oh okay |
17:09:41 | FromDiscord | <.aingel.> Right and then it assigns it to a new var if I do the deref before the add |
17:09:44 | FromDiscord | <.aingel.> Makes sense, thank you! |
17:11:20 | FromDiscord | <raynei486> In reply to @Elegantbeef "It's a C++ term,": ackchually it's something that's addressable 🤓🤓 |
17:13:57 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4GEU |
17:15:03 | * | dza quit (Server closed connection) |
17:16:28 | * | dza joined #nim |
17:20:39 | FromDiscord | <odexine> you're on inim |
17:20:46 | FromDiscord | <odexine> it recompiles the file every expression |
17:21:02 | FromDiscord | <odexine> use a real file and see that the pointer is the same |
17:21:22 | FromDiscord | <odexine> @Phil |
17:21:56 | FromDiscord | <Phil> Dangit |
17:22:23 | FromDiscord | <odexine> next time to verify equality use a single expression |
17:22:38 | FromDiscord | <odexine> echo x.pointer.repr, " ", y.pointer.repr |
17:22:42 | FromDiscord | <odexine> or == if you want |
17:27:55 | * | ntat joined #nim |
17:37:06 | FromDiscord | <Phil> sent a code paste, see https://play.nim-lang.org/#ix=4GEZ |
17:40:35 | FromDiscord | <odexine> Can’t help you there |
17:54:06 | * | ntat quit (Quit: leaving) |
18:01:19 | FromDiscord | <Elegantbeef> Phil we went overthis |
18:01:20 | FromDiscord | <Elegantbeef> First usage generates hooks, you need to declare hooks before any code |
18:01:33 | rockcavera | I was wondering which of the three procedures provides the best performance for a constructor? I verified that in all cases the generated C code is different. https://play.nim-lang.org/#ix=4GF8 |
18:02:32 | FromDiscord | <Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4GF9 |
18:03:04 | FromDiscord | <Elegantbeef> Who cares about the generated C, look at the ASM |
18:03:09 | FromDiscord | <Elegantbeef> Alternatively benchmark it |
18:04:08 | rockcavera | newMyRef1() gives a smaller asm |
18:04:23 | FromDiscord | <can.l> In reply to @Elegantbeef "<@180601887916163073>\: This compiles but": Might be the issue we had before, so maybe we need a `=sink`. It is also very much possible that `g_free` is just the "wrong `free` proc" for the given pointer. |
18:04:51 | FromDiscord | <Elegantbeef> With `-d:release -d:lto` |
18:04:51 | FromDiscord | <Elegantbeef> ? |
18:06:04 | FromDiscord | <Elegantbeef> `g_free` is completely wrong in hindsight |
18:06:04 | FromDiscord | <Elegantbeef> `"lala"` is a constant cstring which resides in `.data` |
18:06:14 | FromDiscord | <Elegantbeef> Freeing it is 100% incorrect behaviour |
18:09:22 | FromDiscord | <Phil> In reply to @Elegantbeef "Freeing it is 100%": That code example is more to demonstrate the double copy |
18:09:28 | FromDiscord | <Phil> (edit) "In reply to @Elegantbeef "Freeing it is 100%": That code example is more to demonstrate the double copy ... " added "proc problem" |
18:09:35 | FromDiscord | <Phil> Which comes into play because =destroy exists |
18:10:11 | FromDiscord | <Phil> In reply to @can.l "Might be the issue": And that one is not the case.↵At least not based on gtk's own docs |
18:10:27 | FromDiscord | <Elegantbeef> I mean in this case `g_free` is 100% wrong so what? |
18:10:45 | FromDiscord | <Chronos [She/Her]> Time to work on my Java backend again |
18:11:48 | FromDiscord | <Phil> In reply to @Elegantbeef "I mean in this": ? The main reason I have the code as it is is to get an example close-ish to what I face in owlkettle.↵In the "real" example the string would be coming from a proc stemming from gtk where g_free definitely is the right choice. Just no clue how I'd simulate that here |
18:14:21 | FromDiscord | <Phil> sent a long message, see http://ix.io/4GFd |
18:14:26 | FromDiscord | <Phil> (edit) "http://ix.io/4GFd" => "http://ix.io/4GFe" |
18:15:36 | FromDiscord | <Chronos [She/Her]> `of '\l': result.add("\\n")` huh |
18:17:01 | FromDiscord | <Phil> Erm... how do you copy a cstring |
18:17:25 | FromDiscord | <Phil> it's not a ref type so `[]` to unref seems a tad weird |
18:22:38 | FromDiscord | <Phil> Heck how the hell do I even define the copy proc without making it recursive |
18:26:22 | FromDiscord | <Phil> In reply to @can.l "Might be the issue": Running into the entire recursive copying issue again that is starting to become mildly frustrating to deal with, particularly for this cstring bit since I have no clue how one is supposed to copy a cstring when you can't unref, you can't copymem because you can't know the size of the string and you can't just assign because that makes things recursive |
18:27:56 | * | junaid_ joined #nim |
18:31:10 | rockcavera | in a small benchmark newMyRef1() seems faster: https://play.nim-lang.org/#ix=4GFi |
18:38:25 | * | def- quit (Quit: -) |
18:38:38 | * | def- joined #nim |
18:41:06 | NimEventer | New question by Philipp Doerner: How do you copy the value of a cstring in nim?, see https://stackoverflow.com/questions/77123150/how-do-you-copy-the-value-of-a-cstring-in-nim |
18:41:33 | NimEventer | New thread by Isofruit: How to define a =copy hook for a distinct cstring type?, see https://forum.nim-lang.org/t/10490 |
18:43:58 | * | lucasta joined #nim |
18:45:04 | FromDiscord | <Phil> Wait a second.... @can.l do we even need a copy-hook for the OwnedGtkString type? |
18:45:48 | FromDiscord | <Phil> We originally only needed one for Pixbuf because simple assignment stuff wouldn't compile otherwise.↵With the cstring stuff... well you get a copy of the pointer, though not the value |
18:48:15 | FromDiscord | <Chronos [She/Her]> Yeah okay I'm better off making my own language oof |
18:50:44 | * | lucasta quit (Remote host closed the connection) |
18:51:08 | * | lucasta joined #nim |
18:51:09 | * | lucasta quit (Remote host closed the connection) |
18:51:37 | NimEventer | New thread by MattRixman: Is there a `terminal.setRaw` on Linux?, see https://forum.nim-lang.org/t/10491 |
18:57:14 | * | disso-peach joined #nim |
19:00:36 | * | disso-peach quit (Client Quit) |
19:11:47 | FromDiscord | <nomad> sent a code paste, see https://play.nim-lang.org/#ix=4GFo |
19:17:43 | FromDiscord | <nnsee> you're missing a dash |
19:18:39 | FromDiscord | <nnsee> it's `--app`, not `-app` |
19:18:57 | FromDiscord | <nnsee> the latter would be parsed as `-a -p -p` |
19:19:08 | FromDiscord | <nnsee> which is why you're getting that error |
19:26:35 | FromDiscord | <can.l> In reply to @isofruit "Running into the entire": Since you need something allocated by GTK (in order to use `g_free`), you can just use https://developer-old.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strdup |
19:30:04 | FromDiscord | <can.l> In reply to @isofruit "Wait a second.... <@893965307171979326>": The question is if Nim just silently uses the wrong `=copy` if none is defined, or if it errors out. Judging from your GH comment, it just silently uses the wrong hook. That is a problem from a software maintenance perspectice, since even if we could verify that no `=copy` is called in the current version, it is basically expected that this will be forgotten about in the fut |
19:36:20 | FromDiscord | <nomad> In reply to @nnsee "it's `--app`, not `-app`": thanks man, i would never have noticed that 😭 |
19:37:16 | FromDiscord | <Phil> In reply to @can.l "The question is if": I think I've got it now, example on the PR |
19:51:51 | * | junaid_ quit (Remote host closed the connection) |
20:14:25 | * | xmachina quit (Quit: WeeChat 4.0.4) |
20:42:12 | FromDiscord | <Elegantbeef> @Phil reading your PR a bit, might be a case of cursors causing your copies not to be made |
20:42:31 | FromDiscord | <Phil> And a cursor is what? |
20:42:31 | FromDiscord | <Elegantbeef> Though these are pointers so it should probably always copy |
20:43:19 | FromDiscord | <Elegantbeef> A cursor is a copy elision, instead of making a copy of a variable the compiler is free to just alias a pointer to that variable if the logic is still correct |
20:43:48 | FromDiscord | <Elegantbeef> https://nim-lang.org/docs/destructors.html#the-cursor-pragma |
20:43:59 | FromDiscord | <Elegantbeef> https://nim-lang.org/docs/destructors.html#cursor-inference-slash-copy-elision |
20:43:59 | FromDiscord | <Phil> elision = leaving sth out? |
20:44:03 | FromDiscord | <Elegantbeef> Whoops wrong manual |
20:44:04 | FromDiscord | <Elegantbeef> Yes |
20:44:16 | FromDiscord | <Elegantbeef> Copy elision is fancy talk for "Skipping a copy" |
20:44:45 | FromDiscord | <Elegantbeef> This of course depends on what you're doing |
20:45:00 | FromDiscord | <_gumbercules> added some jolt physics to my wasm gane engine project thing https://media.discordapp.net/attachments/371759389889003532/1153069114642923571/chrome_W5jOusyAUN.mp4 |
20:45:27 | FromDiscord | <Elegantbeef> Nice, I have expected the human to turn into jelly on collision |
20:45:30 | FromDiscord | <Elegantbeef> half\ |
20:46:18 | FromDiscord | <Elegantbeef> What shadow technique are you using? |
20:46:54 | FromDiscord | <Elegantbeef> Cannot tell if it's artifacting but seems the shadow eases out when it's not touching the ground |
20:48:02 | FromDiscord | <Phil> Ah, good point on the cursor thingy: Managed to trigger a copy by doing assignment to a var and then a let variable as that tends to work in these cases |
20:48:23 | FromDiscord | <_gumbercules> that's probably just some clipping plane / depth stuff I haven't sorted out Elegantbeef |
20:48:27 | FromDiscord | <_gumbercules> It's just regular old shadow mapping |
20:48:58 | FromDiscord | <_gumbercules> https://floooh.github.io/sokol-html5/shadows-sapp.html |
20:49:00 | FromDiscord | <_gumbercules> essentially what you see here |
20:49:40 | * | jmdaemon joined #nim |
20:50:06 | FromDiscord | <_gumbercules> In reply to @Elegantbeef "Nice, I have expected": ragdoll inc |
20:52:57 | FromDiscord | <Phil> Still can't figure out how I'd do code that triggers a sink, but hey, at least I could test the copy hook. |
20:53:17 | FromDiscord | <Elegantbeef> make a proc that takes a `sink` param |
20:53:18 | FromDiscord | <Elegantbeef> or use `move` |
21:05:09 | * | PMunch quit (Quit: leaving) |
21:28:17 | FromDiscord | <starkiller1493> Is there a simple way to copy an object? |
21:33:30 | FromDiscord | <raynei486> [deepCopy](https://nim-lang.org/docs/system.html#deepCopy%2CT)? |
21:38:55 | FromDiscord | <Elegantbeef> `var a = b` |
21:39:21 | FromDiscord | <Elegantbeef> `deepCopy` recursively copies references which might be what you want, but it's also behind a flag on Orc/Arc |
21:39:29 | * | pbsds quit (Ping timeout: 246 seconds) |
21:45:34 | * | pbsds joined #nim |
21:45:45 | FromDiscord | <starkiller1493> thanks, `deepCopy` was what I had in mind, but `var a = b` is enough |
21:52:00 | FromDiscord | <Chronos [She/Her]> In reply to @Elegantbeef "`deepCopy` recursively copies references": Why is it behind a flag? |
21:52:12 | FromDiscord | <Chronos [She/Her]> If people are using deepCopy, wouldn't they know what they're doing? |
21:52:49 | FromDiscord | <Elegantbeef> Cause it can be implemented better as a macro or proc is what Araq has said |
21:53:49 | * | xmachina joined #nim |
21:54:26 | FromDiscord | <Elegantbeef> I do really tend to talk backwards |
21:56:17 | FromDiscord | <.aingel.> When doing cinterop, if I want to access a struct member, do I have to write the whole struct def in nim? |
21:56:40 | FromDiscord | <.aingel.> sent a code paste, see https://play.nim-lang.org/#ix=4GG1 |
21:56:47 | FromDiscord | <Elegantbeef> Yes, or you can use futhark to do it for you |
21:56:54 | Amun-Ra | yes |
21:57:02 | FromDiscord | <.aingel.> sent a code paste, see https://play.nim-lang.org/#ix=4GG2 |
21:57:05 | FromDiscord | <.aingel.> Okay yeah that will take so much of time |
21:57:09 | FromDiscord | <.aingel.> I need to get futhark runnign |
21:57:12 | FromDiscord | <.aingel.> It's not building for me |
21:57:13 | FromDiscord | <Elegantbeef> Or you can use c2nim |
21:57:25 | FromDiscord | <.aingel.> c2nim wasn't working for me either |
21:57:28 | FromDiscord | <Elegantbeef> Install libclang |
21:57:33 | FromDiscord | <.aingel.> Do you run c2nim on the header file? |
21:57:37 | FromDiscord | <.aingel.> Or the c file |
21:57:37 | FromDiscord | <Elegantbeef> yes |
21:58:09 | FromDiscord | <Elegantbeef> The header since you want the ABI not the code transpiled |
21:58:51 | FromDiscord | <.aingel.> Yeah c2nim just outputs a big comment |
21:59:01 | FromDiscord | <Elegantbeef> You likely should do \`gcc -E ./yourheader |
21:59:10 | FromDiscord | <Elegantbeef> to expand the header then remove everything that you do not need |
21:59:22 | FromDiscord | <.aingel.> okay let me try that |
22:00:18 | FromDiscord | <Chronos [She/Her]> In reply to @Elegantbeef "Cause it can be": Better? How so? |
22:00:26 | FromDiscord | <Chronos [She/Her]> You mean by the users themselves? |
22:00:28 | FromDiscord | <Elegantbeef> I didnt say it |
22:00:30 | FromDiscord | <Elegantbeef> So don't ask me |
22:00:40 | FromDiscord | <Chronos [She/Her]> Welp I'm not asking Araq so- |
22:00:57 | FromDiscord | <.aingel.> I'm geetting some wild stuff outta that |
22:01:42 | FromDiscord | <Elegantbeef> Right you need to remove what isnt actually included |
22:01:47 | FromDiscord | <Elegantbeef> Rather what you don't want included |
22:01:48 | FromDiscord | <.aingel.> @ElegantBeouf Also I can't find out how to install libclang on macos |
22:01:53 | FromDiscord | <Chronos [She/Her]> Wouldn't futhark be better? :P |
22:02:07 | FromDiscord | <Elegantbeef> better is subjective afterall |
22:02:12 | FromDiscord | <Elegantbeef> futhark is generally more usable yes |
22:03:37 | FromDiscord | <Chronos [She/Her]> C2Nim requires manual editing while Futhark works quite well afaik excluding any particularly tricky stuff |
22:03:59 | FromDiscord | <.aingel.> Yeah I will try and get futhark working but I think this is a good learning experience anyways though |
22:04:02 | FromDiscord | <.aingel.> To know what exactly is going on |
22:04:21 | FromDiscord | <.aingel.> sent a code paste, see https://play.nim-lang.org/#ix=4GG4 |
22:04:22 | FromDiscord | <.aingel.> Do I also need importc |
22:04:29 | FromDiscord | <Chronos [She/Her]> In reply to @.aingel. "Yeah I will try": Fair |
22:05:54 | FromDiscord | <.aingel.> I'm assuming I don't need importc then if I import the struct like this? |
22:06:03 | FromDiscord | <.aingel.> Or do I/ |
22:06:14 | FromDiscord | <.aingel.> (edit) "I/" => "I" |
22:07:07 | FromDiscord | <Elegantbeef> You do not technically need to but it's good for your health to point at the header file |
22:09:17 | FromDiscord | <.aingel.> Why is it good for health |
22:09:18 | FromDiscord | <.aingel.> just curious |
22:09:54 | FromDiscord | <Elegantbeef> It includes the header and you get C's(albiet limited) type checking |
22:10:53 | FromDiscord | <Elegantbeef> Just lazily doing `gcc -E` on the dom.h then passing it to c2nim gets you something almost usable https://play.nim-lang.org/#ix=4GG5 |
22:11:15 | FromDiscord | <Elegantbeef> Still issues like the inline procs not being properly written or procs not annotated with cdecl, but that sort of stuff is not too bad |
22:12:04 | FromDiscord | <Elegantbeef> Many proc pointers are also not generated, due to attributes I assume |
22:12:15 | FromDiscord | <Elegantbeef> Changing the C macro there would help |
22:12:34 | FromDiscord | <Elegantbeef> Getting libclang installed through brew and using futhark would likely be less work |
22:13:05 | FromDiscord | <.aingel.> Ya |
22:13:17 | FromDiscord | <.aingel.> I think I know enough about how it works internally now to not want to do it |
22:13:46 | FromDiscord | <.aingel.> I have /usr/local/opt/llvm/lib/libclang.dylib |
22:13:48 | FromDiscord | <Elegantbeef> Blame C for being such a silly ABI language 😄 |
22:13:51 | FromDiscord | <.aingel.> haha |
22:13:57 | FromDiscord | <.aingel.> And it's in my path |
22:14:04 | FromDiscord | <Elegantbeef> So install futhark pointing it to that path |
22:14:06 | FromDiscord | <.aingel.> But nimble futhark still says cannot find |
22:14:23 | FromDiscord | <Elegantbeef> using `--passL:-L/Path/To/libclang/dir` |
22:14:29 | FromDiscord | <.aingel.> okie |
22:14:36 | FromDiscord | <Elegantbeef> https://github.com/PMunch/futhark#installation |
22:14:39 | FromDiscord | <Elegantbeef> RTFM people |
22:14:40 | FromDiscord | <Elegantbeef> I swear |
22:15:00 | FromDiscord | <.aingel.> Sorry! |
22:15:52 | FromDiscord | <.aingel.> ` Success: futhark installed successfully.` |
22:15:54 | FromDiscord | <.aingel.> Yay |
22:16:23 | FromDiscord | <Elegantbeef> Excuse me whilst I mutter under by breath about reading |
22:16:45 | FromDiscord | <.aingel.> 😆 |
22:26:23 | FromDiscord | <Chronos [She/Her]> Okay old man, we get it, jeez! |
22:26:46 | FromDiscord | <Elegantbeef> Hey I'm not old, now get of my lawn |
22:36:03 | * | dv^_^ quit (Server closed connection) |
22:36:28 | * | dv^_^ joined #nim |
23:00:14 | * | disso-peach joined #nim |
23:45:58 | * | lumo_e joined #nim |
23:59:42 | FromDiscord | <millymox> Can someone direct me on how to use nim to compile js to be able to use electron? |
23:59:46 | FromDiscord | <millymox> Please |