code style example, setup instructions and bastd.c
This commit is contained in:
parent
7735011928
commit
2c9ce97a0e
4 changed files with 204 additions and 86 deletions
27
README.md
27
README.md
|
@ -56,5 +56,32 @@ in C.
|
|||
|
||||
C is great. Don't let anyone tell you it's not.
|
||||
|
||||
## Setup
|
||||
Download the [latest release](https://github.com/midnadimple/bastd/releases/latest)
|
||||
whenever you want to start a new project.
|
||||
|
||||
All of your code is going to go in the root of this folder, and all the `bastd`
|
||||
code has been kept in the `bastd` folder. FOr convenience, the `bastd.c` file,
|
||||
which includes all other C files in the folder, stays in the top level
|
||||
directory, so you can easily include the file.
|
||||
|
||||
So, open `main.c` and have a scroll through it to see some example code. Then,
|
||||
delete everything in the file and enter this basic skeleton:
|
||||
```c
|
||||
#include "bastd.c"
|
||||
|
||||
CALLBACK Error
|
||||
start(Slice_S8 args, Buffer stdin, Buffer stdout)
|
||||
{
|
||||
return Error_success;
|
||||
}
|
||||
```
|
||||
|
||||
Now, you can compile the program with `build.bat` or `build.sh` to get an
|
||||
executable.
|
||||
|
||||
Note that since you make a new copy of `bastd` for every project, the library
|
||||
is completely vendored and you can modify it however you'd like.
|
||||
|
||||
## LICENSE
|
||||
`bastd` is licensed under the 3-clause BSD license. See [LICENSE.md](LICENSE.md).
|
31
bastd.c
Normal file
31
bastd.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef BASTD_C
|
||||
#define BASTD_C
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef int8_t I8;
|
||||
typedef int16_t I16;
|
||||
typedef int32_t I32;
|
||||
typedef int64_t I64;
|
||||
typedef uint8_t U8;
|
||||
typedef uint16_t U16;
|
||||
typedef uint32_t U32;
|
||||
typedef uint64_t U64;
|
||||
|
||||
typedef float F32;
|
||||
typedef double F64;
|
||||
|
||||
typedef U32 B32;
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#define FUNCTION static
|
||||
#define GLOBAL_VAR static
|
||||
#define LOCAL_PERSIST static
|
||||
|
||||
#define STMNT(s) do{ s }while(0)
|
||||
|
||||
// TODO: Add Linux Version
|
||||
#define ASSERT(x, msg) STMNT(if (!x) __debugbreak();)
|
||||
|
||||
#endif //BASTD_C
|
60
main.c
Normal file
60
main.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include "bastd.c"
|
||||
|
||||
// Single line
|
||||
/* Multi
|
||||
Line */
|
||||
|
||||
// "GLOBAL_VAR" macro expands to "static"
|
||||
GLOBAL_VAR F32 evil_number = 666 // variables names use snake_case
|
||||
|
||||
typedef struct RenderVertex RenderVertex; // typedefs come before structs
|
||||
struct RenderVertex { // struct names use PascalCase
|
||||
F32 x, y, z
|
||||
}
|
||||
|
||||
// Generic pattern. the output type will be "Slice_RenderVertex"
|
||||
#define SLICE_TYPE RenderVertex
|
||||
#include "slice.h"
|
||||
|
||||
// all functions prefixed with "FUNCTION" macro, which expands to "static"
|
||||
FUNCTION I8 // primitive types follow rust style
|
||||
addTwo(I8 a, I8 b) // Function names use camelCase
|
||||
{
|
||||
I8 res = a + b;
|
||||
ASSERT(res != 666, "Ah! The Devil!"); // All macros, regardless of usage, are MACRO_CASE
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Functions called by other functions are prefixed with CALLBACK, which is not
|
||||
defined as "static" , incase you decide to move it to a different
|
||||
compilation unit
|
||||
*/
|
||||
CALLBACK Error
|
||||
start(Slice_S8 args, Buffer stdin, Buffer stdout)
|
||||
{
|
||||
/* all functions that belong to a type or a module are styled
|
||||
"m_TypeName_functionName". "m" is a lower-case shortened version of the
|
||||
module's name (usually 1-3 letters).
|
||||
*/
|
||||
Buffer_appendS8(&stdout, args[0]);
|
||||
Buffer_flush(&stdout);
|
||||
|
||||
r_Window window = r_Window_create(1280, 720, "Bastd Example");
|
||||
I32 frame_number = 0;
|
||||
|
||||
for (!window.should_close) {
|
||||
frame_number += 1;
|
||||
|
||||
// if there is no module, function is styled "TypeName_functionName"
|
||||
Buffer_appendS8(&stdout, "Current frame: ");
|
||||
Buffer_appendI32(&stdout, frame_number);
|
||||
Buffer_appendChar(&stdout, '\n');
|
||||
Buffer_flush(&stdout);
|
||||
|
||||
r_Window_tick(&window);
|
||||
}
|
||||
|
||||
/* Enum names are styled with PascalCase. Enum values are styled
|
||||
"TypeName_value_name"*/
|
||||
return Error_success;
|
||||
}
|
Loading…
Add table
Reference in a new issue