The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
4.2KB

  1. @verbatim
  2. This is a brief description of the LittleFoot language syntax
  3. Littlefoot basically looks like C, but has no pointers, and the only types are:
  4. - int (32-bit signed integer)
  5. - float (32-bit float)
  6. - bool
  7. The top-level syntax of a program is a list of global variables and global functions. Order
  8. of declaration isn't important, you can use functions and variables that are declared later
  9. in the file without needing to pre-declare anything.
  10. Comments are the same format as C/C++/java/etc
  11. So for example:
  12. // global variables. These are initialised to 0 or false when the program is loaded, and
  13. // you can't currently provide any other initial values
  14. int foo, bar;
  15. int getTheNextNumber()
  16. {
  17. return addTwoNumbers (++foo, 2.0) * 3;
  18. }
  19. float addTwoNumbers (int x, float y)
  20. {
  21. return float (x) + y;
  22. }
  23. The usual control-flow operators are provided, all with C++ style syntax:
  24. if/else
  25. for
  26. while
  27. do...while
  28. continue
  29. break
  30. return
  31. (There isn't currently a switch statement though)
  32. Arithmetic ops are the usual suspects, (with the standard operator precedence):
  33. +, -, *, /, %
  34. ||, &&, |, &, ~, ^
  35. ++, --, +=, -=, *=, /=, %=, |=, &=, ^=
  36. ==, !=, <, >, <=, >=, !
  37. <<, >>, <<=, >>=, >>>
  38. Ternary operator (x ? y : z)
  39. Local variables are declared in C++-style syntax:
  40. void foo()
  41. {
  42. int x = 123;
  43. float y = 12.0, z = 1.0e5;
  44. bool b = y > 20.0;
  45. }
  46. Casts of primitive types are done with function-style syntax, e.g.
  47. int x = int (123.0);
  48. float f = float (getIntegerValue());
  49. Arrays of any type can be created in the global scope using C-style syntax.
  50. Elements of arrays can be set and read from functions.
  51. Arrays cannot be created within functions or returned from functions.
  52. For example:
  53. int foo[12];
  54. void initialise()
  55. {
  56. for (int i = 0; i < 12; ++i)
  57. foo[i] = i;
  58. }
  59. The program communicates with the host computer by using a shared area of memory
  60. called the heap which the host can change. There are some built-in functions
  61. available for the program to use to read from the heap:
  62. int getHeapByte (int byteIndex); // reads a single byte from the heap
  63. int getHeapInt (int byteIndex); // reads 4 bytes from the heap as an integer
  64. int getHeapBits (int startBitIndex, int numBits); // reads a sequence of bits from the heap and returns it as an integer
  65. void setHeapByte (int byteIndex, int newValue); // writes a single byte to the heap
  66. void setHeapInt (int byteIndex, int newValue); // writes 4 bytes to the heap
  67. Depending on the context, there will also be some built-in functions that the
  68. program can use to do what it needs to do. Currently in the standard Pad BLOCK program,
  69. you have the following functions available:
  70. int makeARGB (int alpha, int red, int green, int blue); // combines a set of 8-bit ARGB values into a 32-bit colour
  71. int blendARGB (int baseColour, int overlaidColour); // blends the overlaid ARGB colour onto the base one and returns the new colour
  72. void fillPixel (int rgb, int x, int y); // sets a LED colour on the display
  73. void fillRect (int rgb, int x, int y, int width, int height); // fills a rectangle on the display
  74. A BLOCKs program needs to provide a repaint() function which the block will call
  75. at approximately 25Hz to draw the display. For example, here's a simple program that
  76. draws a moving rectangle:
  77. int rectangleX;
  78. void repaint()
  79. {
  80. fillRect (0xff000044, 0, 0, 15, 15); // fill the display with dark blue
  81. fillRect (0xffffffff, rectangleX, 5, 4, 4); // draw a white rectangle
  82. rectangleX = (rectangleX + 1) % 15; // animate our position and make it wrap
  83. }
  84. The host can also send simple event messages to the program, and to receive these you must
  85. provide a function called "handleMessage", e.g.
  86. void handleMessage (int param1, int param2)
  87. {
  88. // do something with the two integer parameters that the app has sent...
  89. }
  90. @endverbatim