Skip to content

Instantly share code, notes, and snippets.

@krayfaus
Created August 1, 2022 18:14
Show Gist options
  • Save krayfaus/391edda20762afadad4f6cd7e777d661 to your computer and use it in GitHub Desktop.
Save krayfaus/391edda20762afadad4f6cd7e777d661 to your computer and use it in GitHub Desktop.
This is not real source code. The extension here is only for minimal highlighting.
Context :: struct
{
allocator : Allocator;
assertion_failure_handler : Assertion_Failure_Handler;
logger : Logger;
}
// 'context' is a reserved keyword.
// It refers to the currently bound context.
// 'action' doesn't need to know the context type.
// What to do in case it's called without the required context? compilation error! -_-
action :: procedure ()
{
print("Mode: {}\n", context.mode);
}
ActionContext :: struct
{
using base: Context;
mode: String;
}
main :: ()
{
action_context : ActionContext = { ...context, "Fast" };
using action_context
{
return action();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment