using

A keyword that lets you import other namespaces into your namespace 1

things :: enum {
  FIRST,
  SECOND
}

enum_test :: () {
  printf("things.FIRST is: %d\n", things.FIRST);
  printf("things.SECOND is: %d\n", things.SECOND);

  using things.members;

  printf("FIRST is: %d\n", FIRST);
  printf("SECOND is: %d\n", SECOND);
}

Function parameters and nested namespaces can be declared with using:

toggle example
print_position_test.jai

using can import a namespace into a struct, and that namespace is addressable: 2

toggle example
door_test.jai

using can import a pointer to a namespace into a struct: 3

toggle example
door_test_pointer.jai

By using pointers to structs, you can control the memory packing of the referenced structs: 4

toggle example
door_test_packed.jai

Composition via using allows fine-grained control over data packing and visitation: 5

Entity_Hot :: Struct {
  position : Vector3;
  orientation : Quaternion;
  scale : float = 1;
  flags : u32;
}

Entity_Cold :: Struct {
  label : ^ u8;
  group : ^ Group;
  // ...more
}

Entity :: struct {
  using hot : ^ Entity_Hot;
  using cold : ^ Entity_Cold;
}

Door :: struct {
  using entity : Entity;
  openness_current : float = 0;
}

using can import a function to be implicitly invoked when accessing members of a struct:

toggle example
door_test_function.jai

  1. using is a keyword that lets you import other namespaces into your namespace.
    “Data-Oriented Demo: SOA, composition.” YouTube, uploaded by Jonathan Blow, Jan 21, 2015, https://youtu.be/ZHqFrNyLlpA?t=1296 

  2. Now that I’m using that, now I can just say FIRST, SECOND, and THIRD down here, without saying things.whatever. I’m just importing those into my namespace directly, into this function.
    “Data-Oriented Demo: SOA, composition.” YouTube, uploaded by Jonathan Blow, Jan 21, 2015, https://youtu.be/ZHqFrNyLlpA?t=1392 

  3. Now the difference is, in the previous function, the thing that we were using was all constants. They didn’t involve storage or anything, it was just a bunch of enums that expand to constants. But now we’re importing a live pointer. [..] We’re using entity, we don’t have to say entity.position.whatever, we’re just saying position.x, position.y, position.z. But what those mean is dereferencing this live pointer that we’re using, rather than constants in some constant namespace.
    “Data-Oriented Demo: SOA, composition.” YouTube, uploaded by Jonathan Blow, Jan 21, 2015, https://youtu.be/ZHqFrNyLlpA?t=1522 

  4. Now that we’ve got our entity in a different place in memory, instead of just new-ing on the heap, which is kind of dumb and doesn’t really help you, we’re going to store them in a more efficient way.
    “Data-Oriented Demo: SOA, composition.” YouTube, uploaded by Jonathan Blow, Jan 21, 2015, https://youtu.be/ZHqFrNyLlpA?t=2330 

  5. What I would like to do, is break an entity into a couple of parts. I want to break in into the part that I want to visit really a lot from tight loops all of the time and that needs to be just cranked through as fast as the cpu can. And then I want to split it into the other part [..] that doesn’t get used as often, they don’t really get used in tight loops, and they’re not as performance critical.
    “Data-Oriented Demo: SOA, composition.” YouTube, uploaded by Jonathan Blow, Jan 21, 2015, https://youtu.be/ZHqFrNyLlpA?t=2605 

jailang 2019 pixeldroid
https://github.com/pixeldroid/jailang
programming pages theme v0.5.21 (https://github.com/pixeldroid/programming-pages)