This is a very small library (one function + one macro) that helps you live reload C code. It should work fine on Unix systems. Patches for making it run on Windows are most welcome!
#include "hotrod.h"
int main() {
HOTROD(mess, 100, "hello");
}
This is equivalent of the following normal function call. Remember to replace it with this in production!
int main() {
mess(100, "hello");
}
This will create a file called 'hot_mess.c'. In this file there will be a stub function for you to fill in. Every time the line with the macro is executed (and you have changed the source file), the code will recompile and a new version of the function will be loaded in.
To access and change global variables in your main program, define them as extern at the top of your stub source file, like so:
extern int global_x;
void foo() {
global_x = 100;
}
Just including sharing a header file that contains the definition of a non-extern global variable will not work. The dynamic library will get its own memory location for this variable (because of default static linkage).
A better solution is to declare each global variables as 'extern' in the header file and 'static' in the implementation file (of your normal source code). Now you can use these variables by including the header file in the stub function. Since the header contains an 'extern' declaration you don't need to add that in your file, just use the variable as normal.
It's not possible to use the same name in two HOTROD() invocations in the same file. Instead, use the HOTROD_LATER() macro in the places where the function will be called later on (you must try to anticipate which place will be called first and put the normal HOTROD() macro there). Also - remember that you can always call the function with it's normal name (like you'd do in the finished program) but remember that the code won't be automatically reloaded in those places.
Check out 'example.c' in this repository.
There are a few extra options you can set from anywhere in your program (most likely at the start).
hotrod_dir = "./temp";
hotrod_extra_includes = (char*[]) { "my_engine.h", "gfx.h", NULL };
hotrod_print_compile_command = true;
char *hotrod_prefix = "";
char *hotrod_compiler = "gcc";
(C) Erik Svedäng 2016-2019
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.