From 17f325ec727f125dde7d9de8080cf8f029bed701 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" Struct fields can be tagged with a string literal to attach meta-infomration which can be used with runtime-type information. Usually this is used to provide transactional information info on how a struct field is encoded to or decoded from another format, but you can store whatever you want within the string literal Struct fields can be tagged with a string literal to attach meta-information which can be used with runtime-type information. Usually this is used to provide transactional information info on how a struct field is encoded to or decoded from another format, but you can store whatever you want within the string literal The The Procedure types are only compatible with the procedures that have the same calling convention and parameter types. When binding to C libraries you’ll often end up using When binding to C libraries you’ll often end up using A SOA is not just useful for high performance scenarios but also for everyday tasks which are normally only achieveable in higher level languages. SOA is not just useful for high performance scenarios but also for everyday tasks which are normally only achievable in higher level languages. The value for a command line define may be an integer, boolean, or string. Currently, no other types are supported. You can read up further on Built-in procedures here. You can read up further on Built-in procedures here. This feature allows you to cover more edge-case situations where you want some code to be compiled on several platforms. However, overly-liberal use of this feature can make it hard to reason about what code is included or not, based on the target platform or architecture.
@@ -3160,7 +3160,7 @@ Panic runs at compile-time. It is functionally equivalent to an Checks if an identifier is defined through the command line, or gives a default value instead. Values can be set with the Struct literals
Struct field tags #
-User :: struct {
flag: bool, // untagged field
age: int "custom whatever information",
@@ -1604,7 +1604,7 @@
Unions #
v: Value
_, ok := v.(bool)
assert(ok)
-#shared_nil
tag normalizes each variant’s nil
value into nil
on assigment. If you assign nil
or zero values to a union with #shared_nil
the union will be nil
. Unions with #shared_nil
require all variants to have a nil
value.#shared_nil
tag normalizes each variant’s nil
value into nil
on assignment. If you assign nil
or zero values to a union with #shared_nil
the union will be nil
. Unions with #shared_nil
require all variants to have a nil
value.Error :: union #shared_nil {
File_Error,
Memory_Error,
@@ -1736,7 +1736,7 @@
Procedure type
proc "c" (n: i32, data: rawptr)
proc "contextless" (s: []int)
proc "c"
and also set the current context. For this you’ll need to explicity set the context.proc "c"
and also set the current context. For this you’ll need to explicitly set the context.typeid
type #typeid
is a unique identifier for an Odin type. This construct is used by the any
type to denote what the underlying data’s type is.a := typeid_of(bool)
@@ -1877,7 +1877,7 @@
SOA Struct Arrays
-soa_zip
and soa_unzip
#soa_zip
is a built-in procedure which allows the user to treat multiple slices as if they are part of the same data structures, utilizing the power of SOA.soa_zip
is a built-in procedure which allows the user to treat multiple slices as if they are part of the same data structures, utilizing the power of SOA.x := []i32{1, 3, 9}
y := []f32{2, 4, 16}
z := []b32{true, false, true}
@@ -2482,7 +2482,7 @@
when
statements Build tags #
#assert(<boolean>)
#panic(<string>)
##assert
with a false
condition, but #panic
has an error message string parameter.#panic(message)
-
+#config(<identifer>, default)
##config(<identifier>, default)
#-define:NAME=VALUE
command line flag.
@@ -3336,7 +3336,7 @@ #defined
#What to do if you get stuck Try doing a text search in one or more of these subdirectories for what you are looking for. Make sure the search is a proper full text search too, such as what
grep
(a popular 3rd party file search program) provides. Be careful that you specify your search correctly, especially if you use regex. Some default searches on some operating systems may miss content that exists in some files by not searching the actual file contents completely or at all, which can be misleading.
Odin’s documentation may be sparse at times, but this sparsity can be worked around effectively by using the above listed resources. Don’t forget they exist.
When working with any system that is still under-development these kinds of techniques are essential for maximizing your effectiveness. Many (perhaps most) real world companies, especially in intense industries such as game development and multimedia often don’t have complete documentation and changes can happen rapidly.
-Self-sufficiency in such a context requires a willlingness to explore these kinds of resources proactively, rather than waiting for documentation that may be slow to come or may not fully cover what things actually do precisely enough.
+Self-sufficiency in such a context requires a willingness to explore these kinds of resources proactively, rather than waiting for documentation that may be slow to come or may not fully cover what things actually do precisely enough.
Don’t be afraid to simply experiment and try to deduce what something is really doing or what features may exist. You may be surprised how much you can still accomplish with just a little bit of patience and thoughtfulness!
Furthermore, even if Odin doesn’t yet have a feature or library that you need, the fact that Odin has bindings to C’s standard library (which are available in the libc package via import "core:c/libc"
) means that any algorithms, example code, documentation, or books originally written for C can also be used to accomplish what you need in Odin. You can then optionally write Odin wrappers around that code to bridge the idiomatic gap better or else just use the C-like code directly. You can also bind to code from any libraries or languages that foreign
can bind to (see the foreign section for more info).
Thus, when necessity calls for it, the entire literature and community of C is still (in effect) available to you in Odin as well. So, any time you are tempted to think “I can’t implement this in Odin yet because there’s not enough documentation” remind yourself that all (or almost all) of C is still available to you, but through a cleaner namespaced interface. Odin is also similar to C anyway, so direct translations of C to Odin (without even using the libc
bindings) may still be relatively easy. In effect, any tutorial or book on C can also be thought of as an Odin resource too in that sense!
#assert(<boolean>)
#panic(<string>)
#config(<identifer>, default)
#config(<identifier>, default)
#defined
#file
, #line
, #procedure
#location()
or #location(<entity>)