Interactive Programming in C (2014)
9 months ago
- #game-development
- #interactive-programming
- #c-programming
- Interactive programming allows modifying and extending a program while it's running, useful for non-batch applications like game development.
- In C, interactive programming can be achieved by building the application as a shared library, though this restricts the use of global or static variables.
- Handmade Hero demonstrated interactive programming in C by using a shared library, with the wrapper program handling library reloading.
- The shared library must avoid global state and be cautious with function pointers to prevent issues after reloading.
- An example with the Game of Life shows how to implement interactive programming in C using a shared library and a wrapper program.
- The wrapper program uses `dlopen`, `dlsym`, and `dlclose` to manage the shared library, checking for updates via the inode of the library file.
- The Game of Life example includes a struct (`game_api`) to encapsulate the API between the wrapper and the shared library, simplifying function pointer management.
- The technique is portable across Unix-like systems using `libdl`, though Windows requires different handling due to file locking behavior.
- Interactive programming in C opens up possibilities for game development and other interactive applications, making development more efficient.