项目作者: anael-seghezzi

项目描述 :
Interactive C live coding environment
高级语言: C++
项目地址: git://github.com/anael-seghezzi/CToy.git
创建时间: 2016-08-23T21:30:37Z
项目社区:https://github.com/anael-seghezzi/CToy

开源协议:Other

下载


C-Toy

C-Toy is an interactive C(99) coding environment based on TCC.

Small, simple, no bullshit. Write cross-platform C code and see the result immediately. No installation or compiler required, download (<4mb), unzip, run CToy and play. Ready for Windows, MacOSX and Linux. Ideal for prototyping, learning, teaching…

Features

  • CToy: program update on file save (use any text editor)
  • CToy_player: to publish your project (dynamic update disabled)
  • API for window managment, inputs, persistent memory…
  • Image processing with MaratisTCL
  • OpenGLES-2
  • OpenAL
  • Portable pen-tablet support (Wacom, etc)
  • Use C-symbols from native dynamic libraries (*.dll etc) : just copy libraries in your_ctoy_path/lib/
  • Pre-built Dear-Imgui suport (https://github.com/ocornut/imgui)
  • Can also compile your project with other compilers (CMake script for gcc, vs, mingw)
  • Emscripten compatible

Download

- CToy 1.06 Win64

- CToy 1.05 MacOSX

- CToy 1.05 Linux64

- [all versions]

Requirement For Linux: OpenAL

Getting started

  • Launch CToy
  • Open src/main.c using your favorite text editor
  • Start coding (samples included)
  • Save your file(s) and see the result in realtime

Usage

C-Toy expects a main file in src/main.c.

But instead of the standad C “main” function, the entry points are “ctoy_begin”, “ctoy_main_loop” and “ctoy_end”.

The compulsory “Hello, World!” program is then (in src/main.c):

  1. #include <ctoy.h> // ctoy API (including frequently used ANSI C libs)
  2. void ctoy_begin() // called at the beginning of the program
  3. {
  4. printf("Hello, World!\n");
  5. }
  6. void ctoy_main_loop() // called at every update of the main loop
  7. {}
  8. void ctoy_end() // called at the end of the program
  9. {}

Every time you modify src/main.c or any other file connected to it (directly or recursively included), C-Toy will recompile and restart the program dynamically.

One other difference with standard C is the use of persistent memory to maintain a bloc of memory intact between recompiles.
For example:

  1. #include <ctoy.h>
  2. void *persistent_memory = NULL;
  3. void ctoy_begin()
  4. {
  5. if (ctoy_t() == 0) {
  6. persistent_memory = calloc(256, 1); // allocate 256 bytes with zero value
  7. ctoy_register_memory(persistent_memory); // register persistent memory
  8. }
  9. else {
  10. persistent_memory = ctoy_retrieve_memory(); // retrieve persistent memory
  11. }
  12. }
  13. void ctoy_main_loop()
  14. {
  15. int *persistent_counter = (int *)persistent_memory; // access a piece of persistent memory
  16. (*persistent_counter)++; // do something with the data
  17. printf("persistent_counter = %d\n", (*persistent_counter)); // print the content
  18. }
  19. void ctoy_end()
  20. {}

(You can store any data that was manually allocated with malloc, it can be an array or a global pointer. Just avoid storing function pointers, as functions addresses may change after recompiles, or update them after calling ctoy_retrieve_memory)

Documentation

C-Toy API: https://github.com/anael-seghezzi/CToy/blob/master/ressources/include/ctoy.h

MaratisTCL: https://github.com/anael-seghezzi/Maratis-Tiny-C-library

OpenGLES2: https://www.khronos.org/registry/OpenGL-Refpages/es2.0/

OpenAL: https://www.openal.org/documentation/OpenAL_Programmers_Guide.pdf

Tutorials and examples

Wiki: https://github.com/anael-seghezzi/CToy/wiki

License

CToy is licensed under the zlib/libpng License.

Building CToy from sources (CMake)

Unix:

  1. mkdir Build
  2. cd Build
  3. cmake -G "Unix Makefiles" ../ -DCMAKE_INSTALL_PREFIX=../bin -DCMAKE_BUILD_TYPE=Release
  4. make
  5. make install

Windows:

  1. mkdir Build
  2. cd Build
  3. cmake -G "Visual Studio 11 Win64" ../ -DCMAKE_INSTALL_PREFIX=../bin

(libtcc.dll and libtcc.dylib where pre-built from a fork of tcc:
libtcc-fork)