 So recently I saw a video that Zodin made where he added heart reloading to his game to his Musializer project and I thought maybe I would implement that into one of my projects whenever I feel like I need it. And so I need it now because it's really annoying. So basically what heart reloading allows you to do is you can recompile code while it's running and you can see the changes in real time. So normally what I would have to do is in order to, let's say I wanted to change the color of this. So right here. Let me just look for the yellow. Alright, let's say I wanted to change this to blue. I could of course always have some sort of editor, but I hard coded it in this case. So if I wanted to change it to blue, I would need to close the program. Turn it back on, recompile, change this to blue, then recompile it. But instead I can just run, just recompile this rendering file into its own library that the main function runs. Then I press H because that's my key bind for a heart reload. And there we go. Yeah, blue. Let's turn it back into yellow. Okay, so I'm going to be showing you how to do this. It's actually pretty simple. It's got a little bit of boilerplate though, which is a little annoying. So what you need for, let me turn this off. I'm going to do a little zooming in. Alright, what you need for heart reloading is you need your main .c file and then library files. So in Linux you're going to be SO for shared, I think shared object files are coming. All the point is they're dynamic libraries. So let's make our main so that for our library file we're going to want to, we're just going to want a, that's all we're going to need for our, now this is going to be, let's do, we're going to have to do a type def. You don't need to do this, but it's just a better work. We're just defining a type. It's just a function pointer to a function of type void. Do I need to do this? Maybe I do. I'll just do it just in case. Okay. Okay, so we're going to need a pointer called library handling and we're going to set that equal to, we're going to need to do dl open and then our file name. So we're going to compile it. We did a hello, a while loop. So our while loop will just be, it will just be coming. Actually we should just um, let's just get rid of this. You don't need to do this, but it's good practice. That's all the code now. The only thing to do left to do is compile. All right. So let me zoom out a bit. You can see the whole thing better. So I think this is, I think this is the whole thing we need to do. Uh, not 100% sure yet. Guess we're going to have to try. Now, usually I should probably learn CMake. I don't, I don't want to feel like it. Build SH files work for me. So yeah, that's what I'm going to do. I don't know, shared, shared goes for the, for the library. Okay. I think I only need to do that shall deal. So up and ready. So one thing you might have noticed when I did the other thing is that I did this said dash and two people this age and I bet into SH. Basically what that means, what that does is I'm only, I'm only running the second line of the build script. So if I just did the whole bill that stage, I would, I would have compiled the whole thing and I don't want to do that. So, maybe that's what CMake is best for. Either way, I think I got it all right. Let's do, okay, we're going to do the whole thing. Oh wait, first thing you need to do is change the library. Hello from the library. And as you can see, it shows up. Pretty, pretty handy. This is pretty useful. I think it might prevent me from doing bugs for making more bugs because typically what would happen is I would write about 300 lines of code without testing them first because I felt too lazy to turn off the computer, not turn off the computer, turn off the program then rerun it again and then do everything. So yeah, let's just do a quick, quick review. We can shut this off now. So we're going to have two things that we're going to be doing. We're going to, this is pretty simple. It can lead to a lot of way of playing. Like in this other case, like in my game. That's not really good. This is what I have to do to reload the library. And all these lines right here, this is what I have to do to initialize it. So let's go back here. So you're going to want to, so first and foremost you're going to want to include DLFCN. And you're going to want to have a pointer called the library handler. I think this just points to the object or to the library, I'm pretty sure. And we're also going to want a function pointer for the function we want to run. So in this case, so these are the, these are the only two things we really want to do. We should have actually just covered this a lot. Now, the function pointer has to be of the same type as the one you're looking for in the library. So in this case it was just a void. Alright, so after that we open, we open the library in the lib handle. We do using DL open, then the path to the file. So in this case it was in the same directory so you just do dot slash. And I'm not really sure what this is for. Let me check. Lazy function call binding. Immediate function call binding. I'm not exactly sure what these do. But yeah, just use lazy. I guess that's the one I saw being used. And then handle the errors. Alright, and then to open the, and to get the function, what you do is you look for the, you do dlsim, the lib handle, and then polo. Actually, I want to, yeah, so dlsim, the library handler, and then the function name. So, you know, and then handle the error as well. Then you could just call the function anywhere as you please. When you want to reload it, you're going to want to, you're going to want to close the library handle and then open it again. And do the whole thing again. So, it's pretty simple. I don't know why I didn't really hear of this before. It's a really useful, it's a really useful thing. Maybe it makes your codes lower. I think everything might just be faster if you statically link it for compiler optimizations and such. Yeah, how long have this video been running for? It's 18 minutes long. All right, you should have gotten the idea by now. I'm just going to wrap a little bit. So yeah, dynamic programming languages aren't all that. You can do this in Windows, Windows MathLinux. This is just a basic functionality that every modern operating system needs to have, the ability to dynamically link libraries. I think that's it. Thanks for watching.