Merge branch 'master' into windows-llvm-11.1.0

This commit is contained in:
gingerBill
2023-04-20 14:01:57 +01:00
139 changed files with 24508 additions and 14253 deletions

2
.gitignore vendored
View File

@@ -22,6 +22,8 @@ bld/
[Oo]bj/
[Ll]og/
![Cc]ore/[Ll]og/
tests/documentation/verify/
tests/documentation/all.odin-doc
# Visual Studio 2015 cache/options directory
.vs/
# Visual Studio Code options directory

View File

@@ -48,8 +48,11 @@ set odin_version_raw="dev-%curr_year%-%curr_month%"
set compiler_flags= -nologo -Oi -TP -fp:precise -Gm- -MP -FC -EHsc- -GR- -GF
set compiler_defines= -DODIN_VERSION_RAW=\"%odin_version_raw%\"
if not exist .git\ goto skip_git_hash
for /f %%i in ('git rev-parse --short HEAD') do set GIT_SHA=%%i
if %ERRORLEVEL% equ 0 set compiler_defines=%compiler_defines% -DGIT_SHA=\"%GIT_SHA%\"
:skip_git_hash
if %nightly% equ 1 set compiler_defines=%compiler_defines% -DNIGHTLY
if %release_mode% EQU 0 ( rem Debug

View File

@@ -4,15 +4,22 @@ set -eu
: ${CXX=clang++}
: ${CPPFLAGS=}
: ${CXXFLAGS=}
: ${INCLUDE_DIRECTORIES=}
: ${LDFLAGS=}
: ${ODIN_VERSION=dev-$(date +"%Y-%m")}
: ${GIT_SHA=}
CPPFLAGS="$CPPFLAGS -DODIN_VERSION_RAW=\"$ODIN_VERSION\""
CXXFLAGS="$CXXFLAGS -std=c++14"
INCLUDE_DIRECTORIES="$INCLUDE_DIRECTORIES -Isrc/"
LDFLAGS="$LDFLAGS -pthread -lm -lstdc++"
GIT_SHA=$(git rev-parse --short HEAD || :)
if [ "$GIT_SHA" ]; then CPPFLAGS="$CPPFLAGS -DGIT_SHA=\"$GIT_SHA\""; fi
if [ -d ".git" ]; then
GIT_SHA=$(git rev-parse --short HEAD || :)
if [ "$GIT_SHA" ]; then
CPPFLAGS="$CPPFLAGS -DGIT_SHA=\"$GIT_SHA\""
fi
fi
DISABLED_WARNINGS="-Wno-switch -Wno-macro-redefined -Wno-unused-value"
OS=$(uname)
@@ -25,11 +32,11 @@ panic() {
version() { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
config_darwin() {
ARCH=$(uname -m)
local ARCH=$(uname -m)
: ${LLVM_CONFIG=llvm-config}
# allow for arm only llvm's with version 13
if [ ARCH == arm64 ]; then
if [ "${ARCH}" == "arm64" ]; then
MIN_LLVM_VERSION=("13.0.0")
else
# allow for x86 / amd64 all llvm versions beginning from 11
@@ -37,7 +44,7 @@ config_darwin() {
fi
if [ $(version $($LLVM_CONFIG --version)) -lt $(version $MIN_LLVM_VERSION) ]; then
if [ ARCH == arm64 ]; then
if [ "${ARCH}" == "arm64" ]; then
panic "Requirement: llvm-config must be base version 13 for arm64"
else
panic "Requirement: llvm-config must be base version greater than 11 for amd64/x86"
@@ -59,11 +66,11 @@ config_freebsd() {
: ${LLVM_CONFIG=}
if [ ! "$LLVM_CONFIG" ]; then
if which llvm-config11 > /dev/null 2>&1; then
if [ -x "$(command -v llvm-config11)" ]; then
LLVM_CONFIG=llvm-config11
elif which llvm-config12 > /dev/null 2>&1; then
elif [ -x "$(command -v llvm-config12)" ]; then
LLVM_CONFIG=llvm-config12
elif which llvm-config13 > /dev/null 2>&1; then
elif [ -x "$(command -v llvm-config13)" ]; then
LLVM_CONFIG=llvm-config13
else
panic "Unable to find LLVM-config"
@@ -86,12 +93,14 @@ config_linux() {
: ${LLVM_CONFIG=}
if [ ! "$LLVM_CONFIG" ]; then
if which llvm-config > /dev/null 2>&1; then
if [ -x "$(command -v llvm-config)" ]; then
LLVM_CONFIG=llvm-config
elif which llvm-config-11 > /dev/null 2>&1; then
elif [ -x "$(command -v llvm-config-11)" ]; then
LLVM_CONFIG=llvm-config-11
elif which llvm-config-11-64 > /dev/null 2>&1; then
elif [ -x "$(command -v llvm-config-11-64)" ]; then
LLVM_CONFIG=llvm-config-11-64
elif [ -x "$(command -v llvm-config-14)" ]; then
LLVM_CONFIG=llvm-config-14
else
panic "Unable to find LLVM-config"
fi
@@ -111,7 +120,7 @@ config_linux() {
LDFLAGS="$LDFLAGS -ldl"
CXXFLAGS="$CXXFLAGS $($LLVM_CONFIG --cxxflags --ldflags)"
LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs --libfiles) -Wl,-rpath=\$ORIGIN"
LDFLAGS="$LDFLAGS $($LLVM_CONFIG --libs core native --system-libs --libfiles) -Wl,-rpath=\$ORIGIN"
# Creates a copy of the llvm library in the build dir, this is meant to support compiler explorer.
# The annoyance is that this copy can be cluttering the development folder. TODO: split staging folders
@@ -135,10 +144,11 @@ build_odin() {
;;
*)
panic "Build mode unsupported!"
;;
esac
set -x
$CXX src/main.cpp src/libtommath.cpp $DISABLED_WARNINGS $CPPFLAGS $CXXFLAGS $EXTRAFLAGS $LDFLAGS -o odin
$CXX src/main.cpp src/libtommath.cpp $DISABLED_WARNINGS $CPPFLAGS $CXXFLAGS $INCLUDE_DIRECTORIES $EXTRAFLAGS $LDFLAGS -o odin
set +x
}
@@ -147,7 +157,7 @@ run_demo() {
}
have_which() {
if ! which which > /dev/null 2>&1; then
if ! [ -x "$(command -v which)" ]; then
panic "Could not find \`which\`"
fi
}
@@ -169,6 +179,7 @@ FreeBSD)
;;
*)
panic "Platform unsupported!"
;;
esac
if [[ $# -eq 0 ]]; then

View File

@@ -9,14 +9,16 @@ package fiat
u1 :: distinct u8
i1 :: distinct i8
cmovznz_u64 :: #force_inline proc "contextless" (arg1: u1, arg2, arg3: u64) -> (out1: u64) {
@(optimization_mode="none")
cmovznz_u64 :: proc "contextless" (arg1: u1, arg2, arg3: u64) -> (out1: u64) {
x1 := (u64(arg1) * 0xffffffffffffffff)
x2 := ((x1 & arg3) | ((~x1) & arg2))
out1 = x2
return
}
cmovznz_u32 :: #force_inline proc "contextless" (arg1: u1, arg2, arg3: u32) -> (out1: u32) {
@(optimization_mode="none")
cmovznz_u32 :: proc "contextless" (arg1: u1, arg2, arg3: u32) -> (out1: u32) {
x1 := (u32(arg1) * 0xffffffff)
x2 := ((x1 & arg3) | ((~x1) & arg2))
out1 = x2

View File

@@ -305,7 +305,8 @@ fe_opp :: proc "contextless" (out1: ^Loose_Field_Element, arg1: ^Tight_Field_Ele
out1[4] = x5
}
fe_cond_assign :: proc "contextless" (out1, arg1: ^Tight_Field_Element, arg2: int) {
@(optimization_mode="none")
fe_cond_assign :: #force_no_inline proc "contextless" (out1, arg1: ^Tight_Field_Element, arg2: int) {
x1 := fiat.cmovznz_u64(fiat.u1(arg2), out1[0], arg1[0])
x2 := fiat.cmovznz_u64(fiat.u1(arg2), out1[1], arg1[1])
x3 := fiat.cmovznz_u64(fiat.u1(arg2), out1[2], arg1[2])
@@ -596,7 +597,8 @@ fe_set :: proc "contextless" (out1, arg1: ^Tight_Field_Element) {
out1[4] = x5
}
fe_cond_swap :: proc "contextless" (out1, out2: ^Tight_Field_Element, arg1: int) {
@(optimization_mode="none")
fe_cond_swap :: #force_no_inline proc "contextless" (out1, out2: ^Tight_Field_Element, arg1: int) {
mask := -u64(arg1)
x := (out1[0] ~ out2[0]) & mask
x1, y1 := out1[0] ~ x, out2[0] ~ x

View File

@@ -201,7 +201,8 @@ fe_opp :: proc "contextless" (out1: ^Loose_Field_Element, arg1: ^Tight_Field_Ele
out1[2] = x3
}
fe_cond_assign :: proc "contextless" (out1, arg1: ^Tight_Field_Element, arg2: bool) {
@(optimization_mode="none")
fe_cond_assign :: #force_no_inline proc "contextless" (out1, arg1: ^Tight_Field_Element, arg2: bool) {
x1 := fiat.cmovznz_u64(fiat.u1(arg2), out1[0], arg1[0])
x2 := fiat.cmovznz_u64(fiat.u1(arg2), out1[1], arg1[1])
x3 := fiat.cmovznz_u64(fiat.u1(arg2), out1[2], arg1[2])
@@ -342,7 +343,8 @@ fe_set :: #force_inline proc "contextless" (out1, arg1: ^Tight_Field_Element) {
out1[2] = x3
}
fe_cond_swap :: proc "contextless" (out1, out2: ^Tight_Field_Element, arg1: bool) {
@(optimization_mode="none")
fe_cond_swap :: #force_no_inline proc "contextless" (out1, out2: ^Tight_Field_Element, arg1: bool) {
mask := -u64(arg1)
x := (out1[0] ~ out2[0]) & mask
x1, y1 := out1[0] ~ x, out2[0] ~ x

View File

@@ -8,15 +8,23 @@ KEY_SIZE :: 32
NONCE_SIZE :: 12
XNONCE_SIZE :: 24
@(private)
_MAX_CTR_IETF :: 0xffffffff
@(private)
_BLOCK_SIZE :: 64
@(private)
_STATE_SIZE_U32 :: 16
@(private)
_ROUNDS :: 20
@(private)
_SIGMA_0 : u32 : 0x61707865
@(private)
_SIGMA_1 : u32 : 0x3320646e
@(private)
_SIGMA_2 : u32 : 0x79622d32
@(private)
_SIGMA_3 : u32 : 0x6b206574
Context :: struct {
@@ -179,6 +187,7 @@ reset :: proc (ctx: ^Context) {
ctx._is_initialized = false
}
@(private)
_do_blocks :: proc (ctx: ^Context, dst, src: []byte, nr_blocks: int) {
// Enforce the maximum consumed keystream per nonce.
//
@@ -441,6 +450,7 @@ _do_blocks :: proc (ctx: ^Context, dst, src: []byte, nr_blocks: int) {
}
}
@(private)
_hchacha20 :: proc (dst, key, nonce: []byte) {
x0, x1, x2, x3 := _SIGMA_0, _SIGMA_1, _SIGMA_2, _SIGMA_3
x4 := util.U32_LE(key[0:4])

View File

@@ -10,8 +10,10 @@ KEY_SIZE :: chacha20.KEY_SIZE
NONCE_SIZE :: chacha20.NONCE_SIZE
TAG_SIZE :: poly1305.TAG_SIZE
@(private)
_P_MAX :: 64 * 0xffffffff // 64 * (2^32-1)
@(private)
_validate_common_slice_sizes :: proc (tag, key, nonce, aad, text: []byte) {
if len(tag) != TAG_SIZE {
panic("crypto/chacha20poly1305: invalid destination tag size")
@@ -37,7 +39,10 @@ _validate_common_slice_sizes :: proc (tag, key, nonce, aad, text: []byte) {
}
}
@(private)
_PAD: [16]byte
@(private)
_update_mac_pad16 :: #force_inline proc (ctx: ^poly1305.Context, x_len: int) {
if pad_len := 16 - (x_len & (16-1)); pad_len != 16 {
poly1305.update(ctx, _PAD[:pad_len])

View File

@@ -26,6 +26,7 @@ compare_constant_time :: proc "contextless" (a, b: []byte) -> int {
//
// The execution time of this routine is constant regardless of the
// contents of the memory being compared.
@(optimization_mode="none")
compare_byte_ptrs_constant_time :: proc "contextless" (a, b: ^byte, n: int) -> int {
x := mem.slice_ptr(a, n)
y := mem.slice_ptr(b, n)

View File

@@ -8,6 +8,7 @@ import "core:mem"
KEY_SIZE :: 32
TAG_SIZE :: 16
@(private)
_BLOCK_SIZE :: 16
sum :: proc (dst, msg, key: []byte) {
@@ -141,6 +142,7 @@ reset :: proc (ctx: ^Context) {
ctx._is_initialized = false
}
@(private)
_blocks :: proc (ctx: ^Context, msg: []byte, final := false) {
n: field.Tight_Field_Element = ---
final_byte := byte(!final)

View File

@@ -6,8 +6,10 @@ import "core:mem"
SCALAR_SIZE :: 32
POINT_SIZE :: 32
@(private)
_BASE_POINT: [32]byte = {9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
@(private)
_scalar_bit :: #force_inline proc "contextless" (s: ^[32]byte, i: int) -> u8 {
if i < 0 {
return 0
@@ -15,6 +17,7 @@ _scalar_bit :: #force_inline proc "contextless" (s: ^[32]byte, i: int) -> u8 {
return (s[i>>3] >> uint(i&7)) & 1
}
@(private)
_scalarmult :: proc (out, scalar, point: ^[32]byte) {
// Montgomery pseduo-multiplication taken from Monocypher.

View File

@@ -42,7 +42,7 @@ write :: proc(w: ^Writer, record: []string) -> io.Error {
}
}
case:
if strings.contains_rune(field, w.comma) >= 0 {
if strings.contains_rune(field, w.comma) {
return true
}
if strings.contains_any(field, CHAR_SET) {

View File

@@ -163,8 +163,9 @@ get_token :: proc(t: ^Tokenizer) -> (token: Token, err: Error) {
skip_alphanum :: proc(t: ^Tokenizer) {
for t.offset < len(t.data) {
switch next_rune(t) {
switch t.r {
case 'A'..='Z', 'a'..='z', '0'..='9', '_':
next_rune(t)
continue
}

View File

@@ -215,6 +215,12 @@ unmarshal_value :: proc(p: ^Parser, v: any) -> (err: Unmarshal_Error) {
}
}
switch dst in &v {
// Handle json.Value as an unknown type
case Value:
dst = parse_value(p) or_return
return
}
#partial switch token.kind {
case .Null:

View File

@@ -22,7 +22,6 @@ import "core:mem"
import "core:strings"
import "core:time"
import "core:os"
/*
Default configuration for DNS resolution.
*/
@@ -108,6 +107,8 @@ resolve :: proc(hostname_and_maybe_port: string) -> (ep4, ep6: Endpoint, err: Ne
err4, err6: Network_Error = ---, ---
ep4, err4 = resolve_ip4(t.hostname)
ep6, err6 = resolve_ip6(t.hostname)
ep4.port = t.port if err4 == nil else 0
ep6.port = t.port if err6 == nil else 0
if err4 != nil && err6 != nil {
err = err4
}

View File

@@ -740,6 +740,7 @@ Struct_Type :: struct {
where_clauses: []^Expr,
is_packed: bool,
is_raw_union: bool,
is_no_copy: bool,
fields: ^Field_List,
name_count: int,
}

View File

@@ -2527,6 +2527,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
align: ^ast.Expr
is_packed: bool
is_raw_union: bool
is_no_copy: bool
fields: ^ast.Field_List
name_count: int
@@ -2560,6 +2561,11 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
error(p, tag.pos, "duplicate struct tag '#%s'", tag.text)
}
is_raw_union = true
case "no_copy":
if is_no_copy {
error(p, tag.pos, "duplicate struct tag '#%s'", tag.text)
}
is_no_copy = true
case:
error(p, tag.pos, "invalid struct tag '#%s", tag.text)
}
@@ -2594,6 +2600,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
st.align = align
st.is_packed = is_packed
st.is_raw_union = is_raw_union
st.is_no_copy = is_no_copy
st.fields = fields
st.name_count = name_count
st.where_token = where_token

View File

@@ -119,6 +119,7 @@ Type_Info_Struct :: struct {
tags: []string,
is_packed: bool,
is_raw_union: bool,
is_no_copy: bool,
custom_align: bool,
equal: Equal_Proc, // set only when the struct has .Comparable set but does not have .Simple_Compare set

View File

@@ -318,6 +318,7 @@ append_elem :: proc(array: ^$T/[dynamic]$E, arg: E, loc := #caller_location) ->
return 0
}
when size_of(E) == 0 {
array := (^Raw_Dynamic_Array)(array)
array.len += 1
return 1
} else {
@@ -351,6 +352,7 @@ append_elems :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location)
}
when size_of(E) == 0 {
array := (^Raw_Dynamic_Array)(array)
array.len += arg_len
return arg_len
} else {

View File

@@ -8,7 +8,17 @@ Decimal :: struct {
decimal_point: int,
neg, trunc: bool,
}
/*
Sets a Decimal from a given string `s`. The string is expected to represent a float. Stores parsed number in the given Decimal structure.
If parsing fails, the Decimal will be left in an undefined state.
**Inputs**
- d: Pointer to a Decimal struct where the parsed result will be stored
- s: The input string representing the floating-point number
**Returns**
- ok: A boolean indicating whether the parsing was successful
*/
set :: proc(d: ^Decimal, s: string) -> (ok: bool) {
d^ = {}
@@ -91,7 +101,16 @@ set :: proc(d: ^Decimal, s: string) -> (ok: bool) {
return i == len(s)
}
/*
Converts a Decimal to a string representation, using the provided buffer as storage.
**Inputs**
- buf: A byte slice buffer to hold the resulting string
- a: The struct to be converted to a string
**Returns**
- A string representation of the Decimal
*/
decimal_to_string :: proc(buf: []byte, a: ^Decimal) -> string {
digit_zero :: proc(buf: []byte) -> int {
for _, i in buf {
@@ -100,7 +119,6 @@ decimal_to_string :: proc(buf: []byte, a: ^Decimal) -> string {
return len(buf)
}
n := 10 + a.count + abs(a.decimal_point)
// TODO(bill): make this work with a buffer that's not big enough
@@ -129,8 +147,12 @@ decimal_to_string :: proc(buf: []byte, a: ^Decimal) -> string {
return string(b[0:w])
}
/*
Trims trailing zeros in the given Decimal, updating the count and decimal_point values as needed.
// trim trailing zeros
**Inputs**
- a: Pointer to the Decimal struct to be trimmed
*/
trim :: proc(a: ^Decimal) {
for a.count > 0 && a.digits[a.count-1] == '0' {
a.count -= 1
@@ -139,8 +161,15 @@ trim :: proc(a: ^Decimal) {
a.decimal_point = 0
}
}
/*
Converts a given u64 integer `idx` to its Decimal representation in the provided Decimal struct.
**Used for internal Decimal Operations.**
**Inputs**
- a: Where the result will be stored
- idx: The value to be assigned to the Decimal
*/
assign :: proc(a: ^Decimal, idx: u64) {
buf: [64]byte
n := 0
@@ -160,9 +189,15 @@ assign :: proc(a: ^Decimal, idx: u64) {
a.decimal_point = a.count
trim(a)
}
/*
Shifts the Decimal value to the right by k positions.
**Used for internal Decimal Operations.**
**Inputs**
- a: The Decimal struct to be shifted
- k: The number of positions to shift right
*/
shift_right :: proc(a: ^Decimal, k: uint) {
r := 0 // read index
w := 0 // write index
@@ -304,7 +339,15 @@ _shift_left_offsets := [?]struct{delta: int, cutoff: string}{
{18, "173472347597680709441192448139190673828125"},
{19, "867361737988403547205962240695953369140625"},
}
/*
Shifts the decimal of the input value to the left by `k` places
WARNING: asserts `k < 61`
**Inputs**
- a: The Decimal to be modified
- k: The number of places to shift the decimal to the left
*/
shift_left :: proc(a: ^Decimal, k: uint) #no_bounds_check {
prefix_less :: #force_inline proc "contextless" (b: []byte, s: string) -> bool #no_bounds_check {
for i in 0..<len(s) {
@@ -359,7 +402,13 @@ shift_left :: proc(a: ^Decimal, k: uint) #no_bounds_check {
a.count = clamp(a.count, 0, len(a.digits))
trim(a)
}
/*
Shifts the decimal of the input value by the specified number of places
**Inputs**
- a: The Decimal to be modified
- i: The number of places to shift the decimal (positive for left shift, negative for right shift)
*/
shift :: proc(a: ^Decimal, i: int) {
uint_size :: 8*size_of(uint)
max_shift :: uint_size-4
@@ -383,7 +432,15 @@ shift :: proc(a: ^Decimal, i: int) {
shift_right(a, uint(-k))
}
}
/*
Determines if the Decimal can be rounded up at the given digit index
**Inputs**
- a: The Decimal to check
- nd: The digit index to consider for rounding up
**Returns** Boolean if can be rounded up at the given index (>=5)
*/
can_round_up :: proc(a: ^Decimal, nd: int) -> bool {
if nd < 0 || nd >= a.count { return false }
if a.digits[nd] == '5' && nd+1 == a.count {
@@ -395,7 +452,13 @@ can_round_up :: proc(a: ^Decimal, nd: int) -> bool {
return a.digits[nd] >= '5'
}
/*
Rounds the Decimal at the given digit index
**Inputs**
- a: The Decimal to be modified
- nd: The digit index to round
*/
round :: proc(a: ^Decimal, nd: int) {
if nd < 0 || nd >= a.count { return }
if can_round_up(a, nd) {
@@ -404,7 +467,13 @@ round :: proc(a: ^Decimal, nd: int) {
round_down(a, nd)
}
}
/*
Rounds the Decimal up at the given digit index
**Inputs**
- a: The Decimal to be modified
- nd: The digit index to round up
*/
round_up :: proc(a: ^Decimal, nd: int) {
if nd < 0 || nd >= a.count { return }
@@ -421,15 +490,60 @@ round_up :: proc(a: ^Decimal, nd: int) {
a.count = 1
a.decimal_point += 1
}
/*
Rounds down the decimal value to the specified number of decimal places
**Inputs**
- a: The Decimal value to be rounded down
- nd: The number of decimal places to round down to
Example:
import "core:fmt"
import "core:strconv/decimal"
round_down_example :: proc() {
d: decimal.Decimal
str := [64]u8{}
ok := decimal.set(&d, "123.456")
decimal.round_down(&d, 5)
fmt.println(decimal.decimal_to_string(str[:], &d))
}
Output:
123.45
*/
round_down :: proc(a: ^Decimal, nd: int) {
if nd < 0 || nd >= a.count { return }
a.count = nd
trim(a)
}
/*
Extracts the rounded integer part of a decimal value
**Inputs**
- a: A pointer to the Decimal value to extract the rounded integer part from
// Extract integer part, rounded appropriately. There are no guarantees about overflow.
WARNING: There are no guarantees about overflow.
**Returns** The rounded integer part of the input decimal value
Example:
import "core:fmt"
import "core:strconv/decimal"
rounded_integer_example :: proc() {
d: decimal.Decimal
ok := decimal.set(&d, "123.456")
fmt.println(decimal.rounded_integer(&d))
}
Output:
123
*/
rounded_integer :: proc(a: ^Decimal) -> u64 {
if a.decimal_point > 20 {
return 0xffff_ffff_ffff_ffff

View File

@@ -20,7 +20,29 @@ _f16_info := Float_Info{10, 5, -15}
_f32_info := Float_Info{23, 8, -127}
_f64_info := Float_Info{52, 11, -1023}
/*
Converts a floating-point number to a string with the specified format and precision.
**Inputs**
buf: A byte slice to store the resulting string
val: The floating-point value to be converted
fmt: The formatting byte, accepted values are 'e', 'E', 'f', 'F', 'g', 'G'
precision: The number of decimal places to round to
bit_size: The size of the floating-point number in bits, valid values are 16, 32, 64
Example:
buf: [32]byte
val := 3.141592
fmt := 'f'
precision := 2
bit_size := 64
result := strconv.generic_ftoa(buf[:], val, fmt, precision, bit_size) -> "3.14"
**Returns**
- A byte slice containing the formatted string
*/
generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, precision, bit_size: int) -> []byte {
bits: u64
flt: ^Float_Info
@@ -95,8 +117,20 @@ generic_ftoa :: proc(buf: []byte, val: f64, fmt: byte, precision, bit_size: int)
return format_digits(buf, shortest, neg, digs, prec, fmt)
}
/*
Converts a decimal floating-point number into a byte buffer with the given format
**Inputs**
- buf: The byte buffer to store the formatted number
- shortest: If true, generates the shortest representation of the number
- neg: If true, the number is negative
- digs: The decimal number to be formatted
- precision: The number of digits after the decimal point
- fmt: The format specifier (accepted values: 'f', 'F', 'e', 'E', 'g', 'G')
**Returns**
- A byte slice containing the formatted decimal floating-point number
*/
format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: Decimal_Slice, precision: int, fmt: byte) -> []byte {
Buffer :: struct {
b: []byte,
@@ -217,7 +251,15 @@ format_digits :: proc(buf: []byte, shortest: bool, neg: bool, digs: Decimal_Slic
}
/*
Rounds the given decimal number to its shortest representation, considering the provided floating-point format
**Inputs**
- d: The decimal number to round
- mant: The mantissa of the floating-point number
- exp: The exponent of the floating-point number
- flt: Pointer to the Float_Info structure containing information about the floating-point format
*/
round_shortest :: proc(d: ^decimal.Decimal, mant: u64, exp: int, flt: ^Float_Info) {
if mant == 0 { // If mantissa is zero, the number is zero
d.count = 0
@@ -284,7 +326,17 @@ round_shortest :: proc(d: ^decimal.Decimal, mant: u64, exp: int, flt: ^Float_Inf
}
}
/*
Converts a decimal number to its floating-point representation with the given format and returns the resulting bits
**Inputs**
- d: Pointer to the decimal number to convert
- info: Pointer to the Float_Info structure containing information about the floating-point format
**Returns**
- b: The bits representing the floating-point number
- overflow: A boolean indicating whether an overflow occurred during conversion
*/
@(private)
decimal_to_float_bits :: proc(d: ^decimal.Decimal, info: ^Float_Info) -> (b: u64, overflow: bool) {
end :: proc "contextless" (d: ^decimal.Decimal, mant: u64, exp: int, info: ^Float_Info) -> (bits: u64) {

View File

@@ -9,7 +9,18 @@ Int_Flags :: bit_set[Int_Flag]
MAX_BASE :: 32
digits := "0123456789abcdefghijklmnopqrstuvwxyz"
/*
Determines whether the given unsigned 64-bit integer is a negative value by interpreting it as a signed integer with the specified bit size.
**Inputs**
- x: The unsigned 64-bit integer to check for negativity
- is_signed: A boolean indicating if the input should be treated as a signed integer
- bit_size: The bit size of the signed integer representation (8, 16, 32, or 64)
**Returns**
- u: The absolute value of the input integer
- neg: A boolean indicating whether the input integer is negative
*/
is_integer_negative :: proc(x: u64, is_signed: bool, bit_size: int) -> (u: u64, neg: bool) {
u = x
if is_signed {
@@ -36,7 +47,21 @@ is_integer_negative :: proc(x: u64, is_signed: bool, bit_size: int) -> (u: u64,
}
return
}
/*
Appends the string representation of an integer to a buffer with specified base, flags, and digit set.
**Inputs**
- buf: The buffer to append the integer representation to
- x: The integer value to convert
- base: The base for the integer representation (2 <= base <= MAX_BASE)
- is_signed: A boolean indicating if the input should be treated as a signed integer
- bit_size: The bit size of the signed integer representation (8, 16, 32, or 64)
- digits: The digit set used for the integer representation
- flags: The Int_Flags bit set to control integer formatting
**Returns**
- The string containing the integer representation appended to the buffer
*/
append_bits :: proc(buf: []byte, x: u64, base: int, is_signed: bool, bit_size: int, digits: string, flags: Int_Flags) -> string {
if base < 2 || base > MAX_BASE {
panic("strconv: illegal base passed to append_bits")
@@ -78,7 +103,18 @@ append_bits :: proc(buf: []byte, x: u64, base: int, is_signed: bool, bit_size: i
copy(buf, out)
return string(buf[0:len(out)])
}
/*
Determines whether the given unsigned 128-bit integer is a negative value by interpreting it as a signed integer with the specified bit size.
**Inputs**
- x: The unsigned 128-bit integer to check for negativity
- is_signed: A boolean indicating if the input should be treated as a signed integer
- bit_size: The bit size of the signed integer representation (8, 16, 32, 64, or 128)
**Returns**
- u: The absolute value of the input integer
- neg: A boolean indicating whether the input integer is negative
*/
is_integer_negative_128 :: proc(x: u128, is_signed: bool, bit_size: int) -> (u: u128, neg: bool) {
u = x
if is_signed {
@@ -109,9 +145,21 @@ is_integer_negative_128 :: proc(x: u128, is_signed: bool, bit_size: int) -> (u:
}
return
}
/*
Appends the string representation of a 128-bit integer to a buffer with specified base, flags, and digit set.
// import "core:runtime"
**Inputs**
- buf: The buffer to append the integer representation to
- x: The 128-bit integer value to convert
- base: The base for the integer representation (2 <= base <= MAX_BASE)
- is_signed: A boolean indicating if the input should be treated as a signed integer
- bit_size: The bit size of the signed integer representation (8, 16, 32, 64, or 128)
- digits: The digit set used for the integer representation
- flags: The Int_Flags bit set to control integer formatting
**Returns**
- The string containing the integer representation appended to the buffer
*/
append_bits_128 :: proc(buf: []byte, x: u128, base: int, is_signed: bool, bit_size: int, digits: string, flags: Int_Flags) -> string {
if base < 2 || base > MAX_BASE {
panic("strconv: illegal base passed to append_bits")

File diff suppressed because it is too large Load Diff

View File

@@ -38,8 +38,8 @@ Inputs:
- c: The char to check for in the Ascii_Set.
Returns:
A boolean indicating if the byte is contained in the Ascii_Set (true) or not (false).
- res: A boolean indicating if the byte is contained in the Ascii_Set (true) or not (false).
*/
ascii_set_contains :: proc(as: Ascii_Set, c: byte) -> bool #no_bounds_check {
ascii_set_contains :: proc(as: Ascii_Set, c: byte) -> (res: bool) #no_bounds_check {
return as[c>>5] & (1<<(c&31)) != 0
}

View File

@@ -3,6 +3,7 @@ package strings
import "core:runtime"
import "core:unicode/utf8"
import "core:strconv"
import "core:mem"
import "core:io"
/*
Type definition for a procedure that flushes a Builder
@@ -31,10 +32,11 @@ Inputs:
- allocator: (default is context.allocator)
Returns:
A new Builder
- res: The new Builder
- err: An optional allocator error if one occured, `nil` otherwise
*/
builder_make_none :: proc(allocator := context.allocator) -> Builder {
return Builder{buf=make([dynamic]byte, allocator)}
builder_make_none :: proc(allocator := context.allocator) -> (res: Builder, err: mem.Allocator_Error) #optional_allocator_error {
return Builder{buf=make([dynamic]byte, allocator) or_return }, nil
}
/*
Produces a Builder with a specified length and cap of max(16,len) byte buffer
@@ -46,10 +48,11 @@ Inputs:
- allocator: (default is context.allocator)
Returns:
A new Builder
- res: The new Builder
- err: An optional allocator error if one occured, `nil` otherwise
*/
builder_make_len :: proc(len: int, allocator := context.allocator) -> Builder {
return Builder{buf=make([dynamic]byte, len, allocator)}
builder_make_len :: proc(len: int, allocator := context.allocator) -> (res: Builder, err: mem.Allocator_Error) #optional_allocator_error {
return Builder{buf=make([dynamic]byte, len, allocator) or_return }, nil
}
/*
Produces a Builder with a specified length and cap
@@ -62,10 +65,11 @@ Inputs:
- allocator: (default is context.allocator)
Returns:
A new Builder
- res: The new Builder
- err: An optional allocator error if one occured, `nil` otherwise
*/
builder_make_len_cap :: proc(len, cap: int, allocator := context.allocator) -> Builder {
return Builder{buf=make([dynamic]byte, len, cap, allocator)}
builder_make_len_cap :: proc(len, cap: int, allocator := context.allocator) -> (res: Builder, err: mem.Allocator_Error) #optional_allocator_error {
return Builder{buf=make([dynamic]byte, len, cap, allocator) or_return }, nil
}
// overload simple `builder_make_*` with or without len / cap parameters
builder_make :: proc{
@@ -84,11 +88,12 @@ Inputs:
- allocator: (default is context.allocator)
Returns:
initialized ^Builder
- res: A pointer to the initialized Builder
- err: An optional allocator error if one occured, `nil` otherwise
*/
builder_init_none :: proc(b: ^Builder, allocator := context.allocator) -> ^Builder {
b.buf = make([dynamic]byte, allocator)
return b
builder_init_none :: proc(b: ^Builder, allocator := context.allocator) -> (res: ^Builder, err: mem.Allocator_Error) #optional_allocator_error {
b.buf = make([dynamic]byte, allocator) or_return
return b, nil
}
/*
Initializes a Builder with a specified length and cap, which is max(len,16)
@@ -102,11 +107,12 @@ Inputs:
- allocator: (default is context.allocator)
Returns:
Initialized ^Builder
- res: A pointer to the initialized Builder
- err: An optional allocator error if one occured, `nil` otherwise
*/
builder_init_len :: proc(b: ^Builder, len: int, allocator := context.allocator) -> ^Builder {
b.buf = make([dynamic]byte, len, allocator)
return b
builder_init_len :: proc(b: ^Builder, len: int, allocator := context.allocator) -> (res: ^Builder, err: mem.Allocator_Error) #optional_allocator_error {
b.buf = make([dynamic]byte, len, allocator) or_return
return b, nil
}
/*
Initializes a Builder with a specified length and cap
@@ -119,11 +125,12 @@ Inputs:
- allocator: (default is context.allocator)
Returns:
A pointer to the initialized Builder
- res: A pointer to the initialized Builder
- err: An optional allocator error if one occured, `nil` otherwise
*/
builder_init_len_cap :: proc(b: ^Builder, len, cap: int, allocator := context.allocator) -> ^Builder {
b.buf = make([dynamic]byte, len, cap, allocator)
return b
builder_init_len_cap :: proc(b: ^Builder, len, cap: int, allocator := context.allocator) -> (res: ^Builder, err: mem.Allocator_Error) #optional_allocator_error {
b.buf = make([dynamic]byte, len, cap, allocator) or_return
return b, nil
}
// Overload simple `builder_init_*` with or without len / ap parameters
builder_init :: proc{
@@ -169,9 +176,9 @@ Inputs:
- b: A pointer to the Builder
Returns:
An io.Stream
- res: the io.Stream
*/
to_stream :: proc(b: ^Builder) -> io.Stream {
to_stream :: proc(b: ^Builder) -> (res: io.Stream) {
return io.Stream{stream_vtable=_builder_stream_vtable, stream_data=b}
}
/*
@@ -180,10 +187,10 @@ Returns an io.Writer from a Builder
Inputs:
- b: A pointer to the Builder
Returns:
An io.Writer
Returns:
- res: The io.Writer
*/
to_writer :: proc(b: ^Builder) -> io.Writer {
to_writer :: proc(b: ^Builder) -> (res: io.Writer) {
return io.to_writer(to_stream(b))
}
/*
@@ -224,7 +231,7 @@ Inputs:
- backing: A slice of bytes to be used as the backing buffer
Returns:
A new Builder
- res: The new Builder
Example:
@@ -245,17 +252,8 @@ Output:
ab
*/
builder_from_bytes :: proc(backing: []byte) -> Builder {
s := transmute(runtime.Raw_Slice)backing
d := runtime.Raw_Dynamic_Array{
data = s.data,
len = 0,
cap = s.len,
allocator = runtime.nil_allocator(),
}
return Builder{
buf = transmute([dynamic]byte)d,
}
builder_from_bytes :: proc(backing: []byte) -> (res: Builder) {
return Builder{ buf = mem.buffer_from_slice(backing) }
}
// Alias to `builder_from_bytes`
builder_from_slice :: builder_from_bytes
@@ -266,9 +264,9 @@ Inputs:
- b: A Builder
Returns:
The contents of the Builder's buffer, as a string
- res: The contents of the Builder's buffer, as a string
*/
to_string :: proc(b: Builder) -> string {
to_string :: proc(b: Builder) -> (res: string) {
return string(b.buf[:])
}
/*
@@ -278,9 +276,9 @@ Inputs:
- b: A Builder
Returns:
The length of the Builder's buffer
- res: The length of the Builder's buffer
*/
builder_len :: proc(b: Builder) -> int {
builder_len :: proc(b: Builder) -> (res: int) {
return len(b.buf)
}
/*
@@ -290,9 +288,9 @@ Inputs:
- b: A Builder
Returns:
The capacity of the Builder's buffer
- res: The capacity of the Builder's buffer
*/
builder_cap :: proc(b: Builder) -> int {
builder_cap :: proc(b: Builder) -> (res: int) {
return cap(b.buf)
}
/*
@@ -302,9 +300,9 @@ Inputs:
- b: A Builder
Returns:
The available space left in the Builder's buffer
- res: The available space left in the Builder's buffer
*/
builder_space :: proc(b: Builder) -> int {
builder_space :: proc(b: Builder) -> (res: int) {
return cap(b.buf) - len(b.buf)
}
/*
@@ -315,7 +313,7 @@ Inputs:
- x: The byte to be appended
Returns:
The number of bytes appended
- n: The number of bytes appended
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
@@ -364,7 +362,7 @@ Example:
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
Returns:
The number of bytes appended
- n: The number of bytes appended
*/
write_bytes :: proc(b: ^Builder, x: []byte) -> (n: int) {
n0 := len(b.buf)
@@ -380,7 +378,8 @@ Inputs:
- r: The rune to be appended
Returns:
The number of bytes written and an io.Error (if any)
- res: The number of bytes written
- err: An io.Error if one occured, `nil` otherwise
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
@@ -401,7 +400,7 @@ Output:
äb
*/
write_rune :: proc(b: ^Builder, r: rune) -> (int, io.Error) {
write_rune :: proc(b: ^Builder, r: rune) -> (res: int, err: io.Error) {
return io.write_rune(to_writer(b), r)
}
/*
@@ -412,7 +411,7 @@ Inputs:
- r: The rune to be appended
Returns:
The number of bytes written
- n: The number of bytes written
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
@@ -445,7 +444,7 @@ Inputs:
- s: The string to be appended
Returns:
The number of bytes written
- n: The number of bytes written
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
@@ -479,7 +478,7 @@ Inputs:
- b: A pointer to the Builder
Returns:
The last byte in the Builder or 0 if empty
- r: The last byte in the Builder or 0 if empty
*/
pop_byte :: proc(b: ^Builder) -> (r: byte) {
if len(b.buf) == 0 {
@@ -498,7 +497,8 @@ Inputs:
- b: A pointer to the Builder
Returns:
The popped rune and its rune width or (0, 0) if empty
- r: The popped rune
- width: The rune width or 0 if the builder was empty
*/
pop_rune :: proc(b: ^Builder) -> (r: rune, width: int) {
if len(b.buf) == 0 {
@@ -519,7 +519,7 @@ Inputs:
- quote: The optional quote character (default is double quotes)
Returns:
The number of bytes written
- n: The number of bytes written
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
@@ -554,7 +554,7 @@ Inputs:
- write_quote: Optional boolean flag to wrap in single-quotes (') (default is true)
Returns:
The number of bytes written
- n: The number of bytes written
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
@@ -598,7 +598,7 @@ Inputs:
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
Returns:
The number of bytes written
- n: The number of bytes written
*/
write_escaped_rune :: proc(b: ^Builder, r: rune, quote: byte, html_safe := false) -> (n: int) {
n, _ = io.write_escaped_rune(to_writer(b), r, quote, html_safe)
@@ -618,7 +618,7 @@ Inputs:
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
Returns:
The number of characters written
- n: The number of characters written
*/
write_float :: proc(b: ^Builder, f: f64, fmt: byte, prec, bit_size: int, always_signed := false) -> (n: int) {
buf: [384]byte
@@ -642,7 +642,7 @@ Inputs:
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
Returns:
The number of characters written
- n: The number of characters written
*/
write_f16 :: proc(b: ^Builder, f: f16, fmt: byte, always_signed := false) -> (n: int) {
buf: [384]byte
@@ -662,7 +662,7 @@ Inputs:
- always_signed: Optional boolean flag to always include the sign
Returns:
The number of characters written
- n: The number of characters written
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
@@ -704,7 +704,7 @@ Inputs:
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
Returns:
The number of characters written
- n: The number of characters written
*/
write_f64 :: proc(b: ^Builder, f: f64, fmt: byte, always_signed := false) -> (n: int) {
buf: [384]byte
@@ -725,7 +725,7 @@ Inputs:
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
Returns:
The number of characters written
- n: The number of characters written
*/
write_u64 :: proc(b: ^Builder, i: u64, base: int = 10) -> (n: int) {
buf: [32]byte
@@ -743,7 +743,7 @@ Inputs:
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
Returns:
The number of characters written
- n: The number of characters written
*/
write_i64 :: proc(b: ^Builder, i: i64, base: int = 10) -> (n: int) {
buf: [32]byte
@@ -761,7 +761,7 @@ Inputs:
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
Returns:
The number of characters written
- n: The number of characters written
*/
write_uint :: proc(b: ^Builder, i: uint, base: int = 10) -> (n: int) {
return write_u64(b, u64(i), base)
@@ -777,7 +777,7 @@ Inputs:
NOTE: The backing dynamic array may be fixed in capacity or fail to resize, `n` states the number actually written.
Returns:
The number of characters written
- n: The number of characters written
*/
write_int :: proc(b: ^Builder, i: int, base: int = 10) -> (n: int) {
return write_i64(b, i64(i), base)

View File

@@ -1,6 +1,7 @@
package strings
import "core:io"
import "core:mem"
import "core:unicode"
import "core:unicode/utf8"
@@ -17,15 +18,16 @@ Inputs:
WARNING: Allocation does not occur when len(s) == 0
Returns:
A valid UTF-8 string with invalid sequences replaced by `replacement`.
- res: A valid UTF-8 string with invalid sequences replaced by `replacement`.
- err: An optional allocator error if one occured, `nil` otherwise
*/
to_valid_utf8 :: proc(s, replacement: string, allocator := context.allocator) -> string {
to_valid_utf8 :: proc(s, replacement: string, allocator := context.allocator) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
if len(s) == 0 {
return ""
return "", nil
}
b: Builder
builder_init(&b, 0, 0, allocator)
builder_init(&b, 0, 0, allocator) or_return
s := s
for c, i in s {
@@ -70,7 +72,7 @@ to_valid_utf8 :: proc(s, replacement: string, allocator := context.allocator) ->
write_string(&b, s[i:][:w])
i += w
}
return to_string(b)
return to_string(b), nil
}
/*
Converts the input string `s` to all lowercase characters.
@@ -82,7 +84,8 @@ Inputs:
- allocator: (default: context.allocator).
Returns:
A new string with all characters converted to lowercase.
- res: The new string with all characters converted to lowercase
- err: An optional allocator error if one occured, `nil` otherwise
Example:
@@ -98,13 +101,13 @@ Output:
test
*/
to_lower :: proc(s: string, allocator := context.allocator) -> string {
to_lower :: proc(s: string, allocator := context.allocator) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
b: Builder
builder_init(&b, 0, len(s), allocator)
builder_init(&b, 0, len(s), allocator) or_return
for r in s {
write_rune(&b, unicode.to_lower(r))
}
return to_string(b)
return to_string(b), nil
}
/*
Converts the input string `s` to all uppercase characters.
@@ -116,7 +119,8 @@ Inputs:
- allocator: (default: context.allocator).
Returns:
A new string with all characters converted to uppercase.
- res: The new string with all characters converted to uppercase
- err: An optional allocator error if one occured, `nil` otherwise
Example:
@@ -132,13 +136,13 @@ Output:
TEST
*/
to_upper :: proc(s: string, allocator := context.allocator) -> string {
to_upper :: proc(s: string, allocator := context.allocator) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
b: Builder
builder_init(&b, 0, len(s), allocator)
builder_init(&b, 0, len(s), allocator) or_return
for r in s {
write_rune(&b, unicode.to_upper(r))
}
return to_string(b)
return to_string(b), nil
}
/*
Checks if the rune `r` is a delimiter (' ', '-', or '_').
@@ -147,9 +151,9 @@ Inputs:
- r: Rune to check for delimiter status.
Returns:
True if `r` is a delimiter, false otherwise.
- res: True if `r` is a delimiter, false otherwise.
*/
is_delimiter :: proc(r: rune) -> bool {
is_delimiter :: proc(r: rune) -> (res: bool) {
return r == '-' || r == '_' || is_space(r)
}
/*
@@ -159,9 +163,9 @@ Inputs:
- r: Rune to check for separator status.
Returns:
True if `r` is a non-alpha or `unicode.is_space` rune.
- res: True if `r` is a non-alpha or `unicode.is_space` rune.
*/
is_separator :: proc(r: rune) -> bool {
is_separator :: proc(r: rune) -> (res: bool) {
if r <= 0x7f {
switch r {
case '0' ..= '9':
@@ -253,13 +257,14 @@ Inputs:
- allocator: (default: context.allocator).
Returns:
A "lowerCamelCase" formatted string.
- res: The converted string
- err: An optional allocator error if one occured, `nil` otherwise
*/
to_camel_case :: proc(s: string, allocator := context.allocator) -> string {
to_camel_case :: proc(s: string, allocator := context.allocator) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
s := s
s = trim_space(s)
b: Builder
builder_init(&b, 0, len(s), allocator)
builder_init(&b, 0, len(s), allocator) or_return
w := to_writer(&b)
string_case_iterator(w, s, proc(w: io.Writer, prev, curr, next: rune) {
@@ -274,7 +279,7 @@ to_camel_case :: proc(s: string, allocator := context.allocator) -> string {
}
})
return to_string(b)
return to_string(b), nil
}
// Alias to `to_pascal_case`
to_upper_camel_case :: to_pascal_case
@@ -288,13 +293,14 @@ Inputs:
- allocator: (default: context.allocator).
Returns:
A "PascalCase" formatted string.
- res: The converted string
- err: An optional allocator error if one occured, `nil` otherwise
*/
to_pascal_case :: proc(s: string, allocator := context.allocator) -> string {
to_pascal_case :: proc(s: string, allocator := context.allocator) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
s := s
s = trim_space(s)
b: Builder
builder_init(&b, 0, len(s), allocator)
builder_init(&b, 0, len(s), allocator) or_return
w := to_writer(&b)
string_case_iterator(w, s, proc(w: io.Writer, prev, curr, next: rune) {
@@ -309,7 +315,7 @@ to_pascal_case :: proc(s: string, allocator := context.allocator) -> string {
}
})
return to_string(b)
return to_string(b), nil
}
/*
Returns a string converted to a delimiter-separated case with configurable casing
@@ -323,7 +329,8 @@ Inputs:
- allocator: (default: context.allocator).
Returns:
The converted string
- res: The converted string
- err: An optional allocator error if one occured, `nil` otherwise
Example:
@@ -348,11 +355,11 @@ to_delimiter_case :: proc(
delimiter: rune,
all_upper_case: bool,
allocator := context.allocator,
) -> string {
) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
s := s
s = trim_space(s)
b: Builder
builder_init(&b, 0, len(s), allocator)
builder_init(&b, 0, len(s), allocator) or_return
w := to_writer(&b)
adjust_case := unicode.to_upper if all_upper_case else unicode.to_lower
@@ -384,7 +391,7 @@ to_delimiter_case :: proc(
io.write_rune(w, adjust_case(curr))
}
return to_string(b)
return to_string(b), nil
}
/*
Converts a string to "snake_case" with all runes lowercased
@@ -396,7 +403,8 @@ Inputs:
- allocator: (default: context.allocator).
Returns:
The converted string
- res: The converted string
- err: An optional allocator error if one occured, `nil` otherwise
Example:
@@ -414,7 +422,7 @@ Output:
hello_world
*/
to_snake_case :: proc(s: string, allocator := context.allocator) -> string {
to_snake_case :: proc(s: string, allocator := context.allocator) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
return to_delimiter_case(s, '_', false, allocator)
}
// Alias for `to_upper_snake_case`
@@ -429,7 +437,8 @@ Inputs:
- allocator: (default: context.allocator).
Returns:
The converted string
- res: The converted string
- err: An optional allocator error if one occured, `nil` otherwise
Example:
@@ -445,7 +454,7 @@ Output:
HELLO_WORLD
*/
to_upper_snake_case :: proc(s: string, allocator := context.allocator) -> string {
to_upper_snake_case :: proc(s: string, allocator := context.allocator) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
return to_delimiter_case(s, '_', true, allocator)
}
/*
@@ -458,7 +467,8 @@ Inputs:
- allocator: (default: context.allocator).
Returns:
The converted string
- res: The converted string
- err: An optional allocator error if one occured, `nil` otherwise
Example:
@@ -474,7 +484,7 @@ Output:
hello-world
*/
to_kebab_case :: proc(s: string, allocator := context.allocator) -> string {
to_kebab_case :: proc(s: string, allocator := context.allocator) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
return to_delimiter_case(s, '-', false, allocator)
}
/*
@@ -487,7 +497,8 @@ Inputs:
- allocator: (default: context.allocator).
Returns:
The converted string
- res: The converted string
- err: An optional allocator error if one occured, `nil` otherwise
Example:
@@ -503,7 +514,7 @@ Output:
HELLO-WORLD
*/
to_upper_kebab_case :: proc(s: string, allocator := context.allocator) -> string {
to_upper_kebab_case :: proc(s: string, allocator := context.allocator) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
return to_delimiter_case(s, '-', true, allocator)
}
/*
@@ -516,7 +527,8 @@ Inputs:
- allocator: (default: context.allocator).
Returns:
The converted string
- res: The converted string
- err: An optional allocator error if one occured, `nil` otherwise
Example:
@@ -532,11 +544,11 @@ Output:
Hello_World
*/
to_ada_case :: proc(s: string, allocator := context.allocator) -> string {
to_ada_case :: proc(s: string, allocator := context.allocator) -> (res: string, err: mem.Allocator_Error) #optional_allocator_error {
s := s
s = trim_space(s)
b: Builder
builder_init(&b, 0, len(s), allocator)
builder_init(&b, 0, len(s), allocator) or_return
w := to_writer(&b)
string_case_iterator(w, s, proc(w: io.Writer, prev, curr, next: rune) {
@@ -552,5 +564,5 @@ to_ada_case :: proc(s: string, allocator := context.allocator) -> string {
}
})
return to_string(b)
return to_string(b), nil
}

View File

@@ -1,6 +1,7 @@
package strings
import "core:runtime"
import "core:mem"
// Custom string entry struct
Intern_Entry :: struct {
@@ -29,10 +30,14 @@ Inputs:
- m: A pointer to the Intern struct to be initialized
- allocator: The allocator for the Intern_Entry strings (Default: context.allocator)
- map_allocator: The allocator for the map of entries (Default: context.allocator)
Returns:
- err: An allocator error if one occured, `nil` otherwise
*/
intern_init :: proc(m: ^Intern, allocator := context.allocator, map_allocator := context.allocator) {
intern_init :: proc(m: ^Intern, allocator := context.allocator, map_allocator := context.allocator) -> (err: mem.Allocator_Error) {
m.allocator = allocator
m.entries = make(map[string]^Intern_Entry, 16, map_allocator)
m.entries = make(map[string]^Intern_Entry, 16, map_allocator) or_return
return nil
}
/*
Frees the map and all its content allocated using the `.allocator`.
@@ -58,7 +63,8 @@ Inputs:
NOTE: The returned string lives as long as the map entry lives.
Returns:
The interned string and an allocator error if any
- str: The interned string
- err: An allocator error if one occured, `nil` otherwise
*/
intern_get :: proc(m: ^Intern, text: string) -> (str: string, err: runtime.Allocator_Error) {
entry := _intern_get_entry(m, text) or_return
@@ -76,7 +82,8 @@ Inputs:
NOTE: The returned cstring lives as long as the map entry lives
Returns:
The interned cstring and an allocator error if any
- str: The interned cstring
- err: An allocator error if one occured, `nil` otherwise
*/
intern_get_cstring :: proc(m: ^Intern, text: string) -> (str: cstring, err: runtime.Allocator_Error) {
entry := _intern_get_entry(m, text) or_return
@@ -93,7 +100,8 @@ Inputs:
- text: The string to be looked up or interned
Returns:
The new or existing interned entry and an allocator error if any
- new_entry: The interned cstring
- err: An allocator error if one occured, `nil` otherwise
*/
_intern_get_entry :: proc(m: ^Intern, text: string) -> (new_entry: ^Intern_Entry, err: runtime.Allocator_Error) #no_bounds_check {
if prev, ok := m.entries[text]; ok {

View File

@@ -32,7 +32,7 @@ Inputs:
- r: A pointer to a Reader struct
Returns:
An io.Stream for the given Reader
- s: An io.Stream for the given Reader
*/
reader_to_stream :: proc(r: ^Reader) -> (s: io.Stream) {
s.stream_data = r
@@ -47,9 +47,9 @@ Inputs:
- s: The input string to be read
Returns:
An io.Reader for the given string
- res: An io.Reader for the given string
*/
to_reader :: proc(r: ^Reader, s: string) -> io.Reader {
to_reader :: proc(r: ^Reader, s: string) -> (res: io.Reader) {
reader_init(r, s)
rr, _ := io.to_reader(reader_to_stream(r))
return rr
@@ -62,9 +62,9 @@ Inputs:
- s: The input string to be read
Returns:
An `io.Reader_At` for the given string
- res: An `io.Reader_At` for the given string
*/
to_reader_at :: proc(r: ^Reader, s: string) -> io.Reader_At {
to_reader_at :: proc(r: ^Reader, s: string) -> (res: io.Reader_At) {
reader_init(r, s)
rr, _ := io.to_reader_at(reader_to_stream(r))
return rr
@@ -76,9 +76,9 @@ Inputs:
- r: A pointer to a Reader struct
Returns:
The remaining length of the Reader
- res: The remaining length of the Reader
*/
reader_length :: proc(r: ^Reader) -> int {
reader_length :: proc(r: ^Reader) -> (res: int) {
if r.i >= i64(len(r.s)) {
return 0
}
@@ -91,9 +91,9 @@ Inputs:
- r: A pointer to a Reader struct
Returns:
The length of the string stored in the Reader
- res: The length of the string stored in the Reader
*/
reader_size :: proc(r: ^Reader) -> i64 {
reader_size :: proc(r: ^Reader) -> (res: i64) {
return i64(len(r.s))
}
/*
@@ -151,7 +151,7 @@ Returns:
- The byte read from the Reader
- err: An `io.Error` if an error occurs while reading, including `.EOF`, otherwise `nil` denotes success.
*/
reader_read_byte :: proc(r: ^Reader) -> (byte, io.Error) {
reader_read_byte :: proc(r: ^Reader) -> (res: byte, err: io.Error) {
r.prev_rune = -1
if r.i >= i64(len(r.s)) {
return 0, .EOF
@@ -167,9 +167,9 @@ Inputs:
- r: A pointer to a Reader struct
Returns:
An `io.Error` if `r.i <= 0` (`.Invalid_Unread`), otherwise `nil` denotes success.
- err: An `io.Error` if `r.i <= 0` (`.Invalid_Unread`), otherwise `nil` denotes success.
*/
reader_unread_byte :: proc(r: ^Reader) -> io.Error {
reader_unread_byte :: proc(r: ^Reader) -> (err: io.Error) {
if r.i <= 0 {
return .Invalid_Unread
}
@@ -211,9 +211,9 @@ Inputs:
WARNING: May only be used once and after a valid `read_rune` call
Returns:
An `io.Error` if an error occurs while unreading (`.Invalid_Unread`), else `nil` denotes success.
- err: An `io.Error` if an error occurs while unreading (`.Invalid_Unread`), else `nil` denotes success.
*/
reader_unread_rune :: proc(r: ^Reader) -> io.Error {
reader_unread_rune :: proc(r: ^Reader) -> (err: io.Error) {
if r.i <= 0 {
return .Invalid_Unread
}
@@ -236,7 +236,7 @@ Returns:
- The absolute offset after seeking
- err: An `io.Error` if an error occurs while seeking (`.Invalid_Whence`, `.Invalid_Offset`)
*/
reader_seek :: proc(r: ^Reader, offset: i64, whence: io.Seek_From) -> (i64, io.Error) {
reader_seek :: proc(r: ^Reader, offset: i64, whence: io.Seek_From) -> (res: i64, err: io.Error) {
r.prev_rune = -1
abs: i64
switch whence {

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@ _ :: vg
// A Wait_Group waits for a collection of threads to finish
//
// A Wait_Group must not be copied after first use
Wait_Group :: struct {
Wait_Group :: struct #no_copy {
counter: int,
mutex: Mutex,
cond: Cond,
@@ -101,7 +101,7 @@ Example:
fmt.println("Finished")
}
*/
Barrier :: struct {
Barrier :: struct #no_copy {
mutex: Mutex,
cond: Cond,
index: int,
@@ -141,7 +141,7 @@ barrier_wait :: proc "contextless" (b: ^Barrier) -> (is_leader: bool) {
}
Auto_Reset_Event :: struct {
Auto_Reset_Event :: struct #no_copy {
// status == 0: Event is reset and no threads are waiting
// status == 1: Event is signaled
// status == -N: Event is reset and N threads are waiting
@@ -172,7 +172,7 @@ auto_reset_event_wait :: proc "contextless" (e: ^Auto_Reset_Event) {
Ticket_Mutex :: struct {
Ticket_Mutex :: struct #no_copy {
ticket: uint,
serving: uint,
}
@@ -194,7 +194,7 @@ ticket_mutex_guard :: proc "contextless" (m: ^Ticket_Mutex) -> bool {
}
Benaphore :: struct {
Benaphore :: struct #no_copy {
counter: i32,
sema: Sema,
}
@@ -222,7 +222,7 @@ benaphore_guard :: proc "contextless" (m: ^Benaphore) -> bool {
return true
}
Recursive_Benaphore :: struct {
Recursive_Benaphore :: struct #no_copy {
counter: int,
owner: int,
recursion: i32,
@@ -284,7 +284,7 @@ recursive_benaphore_guard :: proc "contextless" (m: ^Recursive_Benaphore) -> boo
// Once is a data value that will perform exactly on action.
//
// A Once must not be copied after first use.
Once :: struct {
Once :: struct #no_copy {
m: Mutex,
done: bool,
}
@@ -372,7 +372,7 @@ once_do_with_data_contextless :: proc "contextless" (o: ^Once, fn: proc "context
// blocks for the specified duration.
// * The `unpark` procedure automatically makes the token available if it
// was not already.
Parker :: struct {
Parker :: struct #no_copy {
state: Futex,
}

View File

@@ -11,7 +11,7 @@ current_thread_id :: proc "contextless" () -> int {
// The zero value for a Mutex is an unlocked mutex
//
// A Mutex must not be copied after first use
Mutex :: struct {
Mutex :: struct #no_copy {
impl: _Mutex,
}
@@ -47,7 +47,7 @@ mutex_guard :: proc "contextless" (m: ^Mutex) -> bool {
// The zero value for a RW_Mutex is an unlocked mutex
//
// A RW_Mutex must not be copied after first use
RW_Mutex :: struct {
RW_Mutex :: struct #no_copy {
impl: _RW_Mutex,
}
@@ -111,7 +111,7 @@ rw_mutex_shared_guard :: proc "contextless" (m: ^RW_Mutex) -> bool {
// The zero value for a Recursive_Mutex is an unlocked mutex
//
// A Recursive_Mutex must not be copied after first use
Recursive_Mutex :: struct {
Recursive_Mutex :: struct #no_copy {
impl: _Recursive_Mutex,
}
@@ -144,7 +144,7 @@ recursive_mutex_guard :: proc "contextless" (m: ^Recursive_Mutex) -> bool {
// waiting for signalling the occurence of an event
//
// A Cond must not be copied after first use
Cond :: struct {
Cond :: struct #no_copy {
impl: _Cond,
}
@@ -172,7 +172,7 @@ cond_broadcast :: proc "contextless" (c: ^Cond) {
// Posting to the semaphore increases the count by one, or the provided amount.
//
// A Sema must not be copied after first use
Sema :: struct {
Sema :: struct #no_copy {
impl: _Sema,
}

View File

@@ -13,7 +13,7 @@ Atomic_Mutex_State :: enum Futex {
// The zero value for a Atomic_Mutex is an unlocked mutex
//
// An Atomic_Mutex must not be copied after first use
Atomic_Mutex :: struct {
Atomic_Mutex :: struct #no_copy {
state: Atomic_Mutex_State,
}
@@ -109,7 +109,7 @@ Atomic_RW_Mutex_State_Reader_Mask :: Atomic_RW_Mutex_State(1<<(Atomic_RW_Mutex_S
// The zero value for an Atomic_RW_Mutex is an unlocked mutex
//
// An Atomic_RW_Mutex must not be copied after first use
Atomic_RW_Mutex :: struct {
Atomic_RW_Mutex :: struct #no_copy {
state: Atomic_RW_Mutex_State,
mutex: Atomic_Mutex,
sema: Atomic_Sema,
@@ -222,7 +222,7 @@ atomic_rw_mutex_shared_guard :: proc "contextless" (m: ^Atomic_RW_Mutex) -> bool
// The zero value for a Recursive_Mutex is an unlocked mutex
//
// An Atomic_Recursive_Mutex must not be copied after first use
Atomic_Recursive_Mutex :: struct {
Atomic_Recursive_Mutex :: struct #no_copy {
owner: int,
recursion: int,
mutex: Mutex,
@@ -285,7 +285,7 @@ atomic_recursive_mutex_guard :: proc "contextless" (m: ^Atomic_Recursive_Mutex)
// waiting for signalling the occurence of an event
//
// An Atomic_Cond must not be copied after first use
Atomic_Cond :: struct {
Atomic_Cond :: struct #no_copy {
state: Futex,
}
@@ -320,7 +320,7 @@ atomic_cond_broadcast :: proc "contextless" (c: ^Atomic_Cond) {
// Posting to the semaphore increases the count by one, or the provided amount.
//
// An Atomic_Sema must not be copied after first use
Atomic_Sema :: struct {
Atomic_Sema :: struct #no_copy {
count: Futex,
}

View File

@@ -52,7 +52,7 @@ foreign advapi32 {
dwCreationFlags: DWORD,
lpEnvironment: LPVOID,
lpCurrentDirectory: wstring,
lpStartupInfo: LPSTARTUPINFO,
lpStartupInfo: LPSTARTUPINFOW,
lpProcessInformation: LPPROCESS_INFORMATION,
) -> BOOL ---
@@ -67,7 +67,7 @@ foreign advapi32 {
dwCreationFlags: DWORD,
lpEnvironment: LPVOID,
lpCurrentDirectory: wstring,
lpStartupInfo: LPSTARTUPINFO,
lpStartupInfo: LPSTARTUPINFOW,
lpProcessInformation: LPPROCESS_INFORMATION,
) -> BOOL ---

View File

@@ -193,9 +193,10 @@ foreign kernel32 {
dwCreationFlags: DWORD,
lpEnvironment: LPVOID,
lpCurrentDirectory: LPCWSTR,
lpStartupInfo: LPSTARTUPINFO,
lpStartupInfo: LPSTARTUPINFOW,
lpProcessInformation: LPPROCESS_INFORMATION,
) -> BOOL ---
GetStartupInfoW :: proc(lpStartupInfo: LPSTARTUPINFOW) ---
GetEnvironmentVariableW :: proc(n: LPCWSTR, v: LPWSTR, nsize: DWORD) -> DWORD ---
SetEnvironmentVariableW :: proc(n: LPCWSTR, v: LPCWSTR) -> BOOL ---
GetEnvironmentStringsW :: proc() -> LPWCH ---
@@ -404,8 +405,87 @@ foreign kernel32 {
) -> BOOL ---
GetLogicalProcessorInformation :: proc(buffer: ^SYSTEM_LOGICAL_PROCESSOR_INFORMATION, returnedLength: PDWORD) -> BOOL ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setfilecompletionnotificationmodes)
SetFileCompletionNotificationModes :: proc(FileHandle: HANDLE, Flags: u8) -> BOOL ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-createiocompletionport)
CreateIoCompletionPort :: proc(FileHandle: HANDLE, ExistingCompletionPort: HANDLE, CompletionKey: ^uintptr, NumberOfConcurrentThreads: DWORD) -> HANDLE ---
//[MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-getqueuedcompletionstatus)
GetQueuedCompletionStatus :: proc(CompletionPort: HANDLE, lpNumberOfBytesTransferred: ^DWORD, lpCompletionKey: uintptr, lpOverlapped: ^^OVERLAPPED, dwMilliseconds: DWORD) -> BOOL ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-getqueuedcompletionstatusex)
GetQueuedCompletionStatusEx :: proc(CompletionPort: HANDLE, lpCompletionPortEntries: ^OVERLAPPED_ENTRY, ulCount: c_ulong, ulNumEntriesRemoved: ^c_ulong, dwMilliseconds: DWORD, fAlertable: BOOL) -> BOOL ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/ioapiset/nf-ioapiset-postqueuedcompletionstatus)
PostQueuedCompletionStatus :: proc(CompletionPort: HANDLE, dwNumberOfBytesTransferred: DWORD, dwCompletionKey: c_ulong, lpOverlapped: ^OVERLAPPED) -> BOOL ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-gethandleinformation)
GetHandleInformation :: proc(hObject: HANDLE, lpdwFlags: ^DWORD) -> BOOL ---
}
DEBUG_PROCESS :: 0x00000001
DEBUG_ONLY_THIS_PROCESS :: 0x00000002
CREATE_SUSPENDED :: 0x00000004
DETACHED_PROCESS :: 0x00000008
CREATE_NEW_CONSOLE :: 0x00000010
NORMAL_PRIORITY_CLASS :: 0x00000020
IDLE_PRIORITY_CLASS :: 0x00000040
HIGH_PRIORITY_CLASS :: 0x00000080
REALTIME_PRIORITY_CLASS :: 0x00000100
CREATE_NEW_PROCESS_GROUP :: 0x00000200
CREATE_UNICODE_ENVIRONMENT :: 0x00000400
CREATE_SEPARATE_WOW_VDM :: 0x00000800
CREATE_SHARED_WOW_VDM :: 0x00001000
CREATE_FORCEDOS :: 0x00002000
BELOW_NORMAL_PRIORITY_CLASS :: 0x00004000
ABOVE_NORMAL_PRIORITY_CLASS :: 0x00008000
INHERIT_PARENT_AFFINITY :: 0x00010000
INHERIT_CALLER_PRIORITY :: 0x00020000 // Deprecated
CREATE_PROTECTED_PROCESS :: 0x00040000
EXTENDED_STARTUPINFO_PRESENT :: 0x00080000
PROCESS_MODE_BACKGROUND_BEGIN :: 0x00100000
PROCESS_MODE_BACKGROUND_END :: 0x00200000
CREATE_SECURE_PROCESS :: 0x00400000
CREATE_BREAKAWAY_FROM_JOB :: 0x01000000
CREATE_PRESERVE_CODE_AUTHZ_LEVEL :: 0x02000000
CREATE_DEFAULT_ERROR_MODE :: 0x04000000
CREATE_NO_WINDOW :: 0x08000000
PROFILE_USER :: 0x10000000
PROFILE_KERNEL :: 0x20000000
PROFILE_SERVER :: 0x40000000
CREATE_IGNORE_SYSTEM_DEFAULT :: 0x80000000
THREAD_BASE_PRIORITY_LOWRT :: 15 // value that gets a thread to LowRealtime-1
THREAD_BASE_PRIORITY_MAX :: 2 // maximum thread base priority boost
THREAD_BASE_PRIORITY_MIN :: (-2) // minimum thread base priority boost
THREAD_BASE_PRIORITY_IDLE :: (-15) // value that gets a thread to idle
THREAD_PRIORITY_LOWEST :: THREAD_BASE_PRIORITY_MIN
THREAD_PRIORITY_BELOW_NORMAL :: (THREAD_PRIORITY_LOWEST+1)
THREAD_PRIORITY_NORMAL :: 0
THREAD_PRIORITY_HIGHEST :: THREAD_BASE_PRIORITY_MAX
THREAD_PRIORITY_ABOVE_NORMAL :: (THREAD_PRIORITY_HIGHEST-1)
THREAD_PRIORITY_ERROR_RETURN :: (MAXLONG)
THREAD_PRIORITY_TIME_CRITICAL :: THREAD_BASE_PRIORITY_LOWRT
THREAD_PRIORITY_IDLE :: THREAD_BASE_PRIORITY_IDLE
THREAD_MODE_BACKGROUND_BEGIN :: 0x00010000
THREAD_MODE_BACKGROUND_END :: 0x00020000
COPY_FILE_FAIL_IF_EXISTS :: 0x00000001
COPY_FILE_RESTARTABLE :: 0x00000002
COPY_FILE_OPEN_SOURCE_FOR_WRITE :: 0x00000004
COPY_FILE_ALLOW_DECRYPTED_DESTINATION :: 0x00000008
COPY_FILE_COPY_SYMLINK :: 0x00000800
COPY_FILE_NO_BUFFERING :: 0x00001000
COPY_FILE_REQUEST_SECURITY_PRIVILEGES :: 0x00002000
COPY_FILE_RESUME_FROM_PAUSE :: 0x00004000
COPY_FILE_NO_OFFLOAD :: 0x00040000
COPY_FILE_IGNORE_EDP_BLOCK :: 0x00400000
COPY_FILE_IGNORE_SOURCE_ENCRYPTION :: 0x00800000
COPY_FILE_DONT_REQUEST_DEST_WRITE_DAC :: 0x02000000
COPY_FILE_REQUEST_COMPRESSED_TRAFFIC :: 0x10000000
COPY_FILE_OPEN_AND_COPY_REPARSE_POINT :: 0x00200000
COPY_FILE_DIRECTORY :: 0x00000080
COPY_FILE_SKIP_ALTERNATE_STREAMS :: 0x00008000
COPY_FILE_DISABLE_PRE_ALLOCATION :: 0x04000000
COPY_FILE_ENABLE_LOW_FREE_SPACE_MODE :: 0x08000000
SECTION_QUERY :: DWORD(0x0001)
SECTION_MAP_WRITE :: DWORD(0x0002)

View File

@@ -111,7 +111,7 @@ LPOVERLAPPED :: ^OVERLAPPED
LPPROCESS_INFORMATION :: ^PROCESS_INFORMATION
PSECURITY_ATTRIBUTES :: ^SECURITY_ATTRIBUTES
LPSECURITY_ATTRIBUTES :: ^SECURITY_ATTRIBUTES
LPSTARTUPINFO :: ^STARTUPINFO
LPSTARTUPINFOW :: ^STARTUPINFOW
LPTRACKMOUSEEVENT :: ^TRACKMOUSEEVENT
VOID :: rawptr
PVOID :: rawptr
@@ -162,6 +162,8 @@ SIZE :: struct {
PSIZE :: ^SIZE
LPSIZE :: ^SIZE
MAXLONG :: 0x7fffffff
FILE_ATTRIBUTE_READONLY: DWORD : 0x00000001
FILE_ATTRIBUTE_HIDDEN: DWORD : 0x00000002
FILE_ATTRIBUTE_SYSTEM: DWORD : 0x00000004
@@ -2042,7 +2044,6 @@ TLS_OUT_OF_INDEXES: DWORD : 0xFFFFFFFF
DLL_THREAD_DETACH: DWORD : 3
DLL_PROCESS_DETACH: DWORD : 0
CREATE_SUSPENDED :: DWORD(0x00000004)
INFINITE :: ~DWORD(0)
@@ -2051,11 +2052,6 @@ DUPLICATE_SAME_ACCESS: DWORD : 0x00000002
CONDITION_VARIABLE_INIT :: CONDITION_VARIABLE{}
SRWLOCK_INIT :: SRWLOCK{}
DETACHED_PROCESS: DWORD : 0x00000008
CREATE_NEW_CONSOLE: DWORD : 0x00000010
CREATE_NO_WINDOW: DWORD : 0x08000000
CREATE_NEW_PROCESS_GROUP: DWORD : 0x00000200
CREATE_UNICODE_ENVIRONMENT: DWORD : 0x00000400
STARTF_USESTDHANDLES: DWORD : 0x00000100
VOLUME_NAME_DOS: DWORD : 0x0
@@ -2418,8 +2414,7 @@ PROCESS_INFORMATION :: struct {
dwThreadId: DWORD,
}
// FYI: This is STARTUPINFOW, not STARTUPINFOA
STARTUPINFO :: struct {
STARTUPINFOW :: struct {
cb: DWORD,
lpReserved: LPWSTR,
lpDesktop: LPWSTR,
@@ -2450,6 +2445,20 @@ FILETIME_as_unix_nanoseconds :: proc "contextless" (ft: FILETIME) -> i64 {
return (t - 116444736000000000) * 100
}
OBJECT_ATTRIBUTES :: struct {
Length: c_ulong,
RootDirectory: HANDLE,
ObjectName: ^UNICODE_STRING,
Attributes: c_ulong,
SecurityDescriptor: rawptr,
SecurityQualityOfService: rawptr,
}
UNICODE_STRING :: struct {
Length: u16,
MaximumLength: u16,
Buffer: ^u16,
}
OVERLAPPED :: struct {
Internal: ^c_ulong,
@@ -2459,6 +2468,13 @@ OVERLAPPED :: struct {
hEvent: HANDLE,
}
OVERLAPPED_ENTRY :: struct {
lpCompletionKey: c_ulong,
lpOverlapped: ^OVERLAPPED,
Internal: c_ulong,
dwNumberOfBytesTransferred: DWORD,
}
LPOVERLAPPED_COMPLETION_ROUTINE :: #type proc "stdcall" (
dwErrorCode: DWORD,
dwNumberOfBytesTransfered: DWORD,

View File

@@ -212,7 +212,7 @@ foreign user32 {
GetRegisteredRawInputDevices :: proc(pRawInputDevices: PRAWINPUTDEVICE, puiNumDevices: PUINT, cbSize: UINT) -> UINT ---
RegisterRawInputDevices :: proc(pRawInputDevices: PCRAWINPUTDEVICE, uiNumDevices: UINT, cbSize: UINT) -> BOOL ---
SendInput :: proc(cInputs: UINT, pInputs: [^]INPUT, cbSize: ^c_int) -> UINT ---
SendInput :: proc(cInputs: UINT, pInputs: [^]INPUT, cbSize: c_int) -> UINT ---
SetLayeredWindowAttributes :: proc(hWnd: HWND, crKey: COLORREF, bAlpha: BYTE, dwFlags: DWORD) -> BOOL ---

View File

@@ -457,8 +457,8 @@ run_as_user :: proc(username, password, application, commandline: string, pi: ^P
// err := GetLastError();
// fmt.printf("GetLastError: %v\n", err);
}
si := STARTUPINFO{}
si.cb = size_of(STARTUPINFO)
si := STARTUPINFOW{}
si.cb = size_of(STARTUPINFOW)
pi := pi
ok = bool(CreateProcessAsUserW(

View File

@@ -1,18 +1,78 @@
// +build windows
package sys_windows
foreign import ws2_32 "system:Ws2_32.lib"
// Define flags to be used with the WSAAsyncSelect() call.
FD_READ :: 0x01
FD_WRITE :: 0x02
FD_OOB :: 0x04
FD_ACCEPT :: 0x08
FD_CONNECT :: 0x10
FD_CLOSE :: 0x20
FD_MAX_EVENTS :: 10
INADDR_LOOPBACK :: 0x7f000001
// Event flag definitions for WSAPoll().
POLLRDNORM :: 0x0100
POLLRDBAND :: 0x0200
POLLIN :: (POLLRDNORM | POLLRDBAND)
POLLPRI :: 0x0400
POLLWRNORM :: 0x0010
POLLOUT :: (POLLWRNORM)
POLLWRBAND :: 0x0020
POLLERR :: 0x0001
POLLHUP :: 0x0002
POLLNVAL :: 0x0004
WSA_POLLFD::struct{
fd:SOCKET,
events:c_short,
revents:c_short,
}
WSANETWORKEVENTS :: struct {
lNetworkEvents: c_long,
iErrorCode: [FD_MAX_EVENTS]c_int,
}
WSAEVENT :: HANDLE
WSAID_ACCEPTEX :: GUID{0xb5367df1, 0xcbac, 0x11cf, {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
WSAID_GETACCEPTEXSOCKADDRS :: GUID{0xb5367df2, 0xcbac, 0x11cf, {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
SIO_GET_EXTENSION_FUNCTION_POINTER :: IOC_INOUT | IOC_WS2 | 6
IOC_OUT :: 0x40000000
IOC_IN :: 0x80000000
IOC_INOUT :: (IOC_IN | IOC_OUT)
IOC_WS2 :: 0x08000000
/*
Example Load:
load_accept_ex :: proc(listener: SOCKET, fn_acceptex: rawptr) {
bytes: u32
guid_accept_ex := WSAID_ACCEPTEX
rc := WSAIoctl(listener, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid_accept_ex, size_of(guid_accept_ex),
fn_acceptex, size_of(fn_acceptex), &bytes, nil, nil,)
assert(rc != windows.SOCKET_ERROR)
}
*/
foreign import ws2_32 "system:Ws2_32.lib"
@(default_calling_convention="stdcall")
foreign ws2_32 {
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsastartup)
WSAStartup :: proc(wVersionRequested: WORD, lpWSAData: LPWSADATA) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsacleanup)
WSACleanup :: proc() -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsagetlasterror)
WSAGetLastError :: proc() -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsapoll)
WSAPoll :: proc(fdArray: ^WSA_POLLFD, fds: c_ulong, timeout: c_int) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaduplicatesocketw)
WSADuplicateSocketW :: proc(
s: SOCKET,
dwProcessId: DWORD,
lpProtocolInfo: LPWSAPROTOCOL_INFO,
) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasend)
WSASend :: proc(
s: SOCKET,
lpBuffers: LPWSABUF,
@@ -22,6 +82,7 @@ foreign ws2_32 {
lpOverlapped: LPWSAOVERLAPPED,
lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsarecv)
WSARecv :: proc(
s: SOCKET,
lpBuffers: LPWSABUF,
@@ -31,6 +92,7 @@ foreign ws2_32 {
lpOverlapped: LPWSAOVERLAPPED,
lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE,
) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw)
WSASocketW :: proc(
af: c_int,
kind: c_int,
@@ -39,16 +101,32 @@ foreign ws2_32 {
g: GROUP,
dwFlags: DWORD,
) -> SOCKET ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaioctl)
WSAIoctl :: proc(s: SOCKET, dwIoControlCode: DWORD, lpvInBuffer: rawptr, cbInBuffer: DWORD, lpvOutBuffer: rawptr, cbOutBuffer: DWORD, lpcbBytesReturned: ^DWORD, lpOverlapped: ^OVERLAPPED, lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaeventselect)
WSAEventSelect :: proc(s: SOCKET, hEventObject: WSAEVENT, lNetworkEvents: i32) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsawaitformultipleevents)
WSAWaitForMultipleEvents :: proc(cEvents: DWORD, lphEvents: ^WSAEVENT, fWaitAll: BOOL, dwTimeout: DWORD, fAlertable: BOOL) -> DWORD ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsaenumnetworkevents)
WSAEnumNetworkEvents :: proc(s: SOCKET, hEventObject: WSAEVENT, lpNetworkEvents: ^WSANETWORKEVENTS) -> c_int ---
//[MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsagetoverlappedresult)
WSAGetOverlappedResult :: proc(s: SOCKET, lpOverlapped: ^OVERLAPPED, lpcbTransfer: ^DWORD, fWait: BOOL, lpdwFlags: ^DWORD) -> BOOL ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-socket)
socket :: proc(
af: c_int,
type: c_int,
protocol: c_int,
) -> SOCKET ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-ioctlsocket)
ioctlsocket :: proc(s: SOCKET, cmd: c_long, argp: ^c_ulong) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-closesocket)
closesocket :: proc(socket: SOCKET) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv)
recv :: proc(socket: SOCKET, buf: rawptr, len: c_int, flags: c_int) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send)
send :: proc(socket: SOCKET, buf: rawptr, len: c_int, flags: c_int) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-recvfrom)
recvfrom :: proc(
socket: SOCKET,
buf: rawptr,
@@ -57,6 +135,7 @@ foreign ws2_32 {
addr: ^SOCKADDR_STORAGE_LH,
addrlen: ^c_int,
) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto)
sendto :: proc(
socket: SOCKET,
buf: rawptr,
@@ -65,9 +144,12 @@ foreign ws2_32 {
addr: ^SOCKADDR_STORAGE_LH,
addrlen: c_int,
) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-shutdown)
shutdown :: proc(socket: SOCKET, how: c_int) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-accept)
accept :: proc(socket: SOCKET, address: ^SOCKADDR_STORAGE_LH, address_len: ^c_int) -> SOCKET ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-setsockopt)
setsockopt :: proc(
s: SOCKET,
level: c_int,
@@ -75,19 +157,28 @@ foreign ws2_32 {
optval: rawptr,
optlen: c_int,
) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockname)
getsockname :: proc(socket: SOCKET, address: ^SOCKADDR_STORAGE_LH, address_len: ^c_int) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getpeername)
getpeername :: proc(socket: SOCKET, address: ^SOCKADDR_STORAGE_LH, address_len: ^c_int) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-bind)
bind :: proc(socket: SOCKET, address: ^SOCKADDR_STORAGE_LH, address_len: socklen_t) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-listen)
listen :: proc(socket: SOCKET, backlog: c_int) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect)
connect :: proc(socket: SOCKET, address: ^SOCKADDR_STORAGE_LH, len: c_int) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo)
getaddrinfo :: proc(
node: cstring,
service: cstring,
hints: ^ADDRINFOA,
res: ^^ADDRINFOA,
) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-freeaddrinfo)
freeaddrinfo :: proc(res: ^ADDRINFOA) ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-freeaddrinfoexw)
FreeAddrInfoExW :: proc(pAddrInfoEx: PADDRINFOEXW) ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfoexw)
GetAddrInfoExW :: proc(
pName: PCWSTR,
pServiceName: PCWSTR,
@@ -99,7 +190,7 @@ foreign ws2_32 {
lpOverlapped: LPOVERLAPPED,
lpCompletionRoutine: LPLOOKUPSERVICE_COMPLETION_ROUTINE,
lpHandle: LPHANDLE) -> INT ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select)
select :: proc(
nfds: c_int,
readfds: ^fd_set,
@@ -107,6 +198,7 @@ foreign ws2_32 {
exceptfds: ^fd_set,
timeout: ^timeval,
) -> c_int ---
// [MS-Docs](https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-getsockopt)
getsockopt :: proc(
s: SOCKET,
level: c_int,
@@ -114,5 +206,4 @@ foreign ws2_32 {
optval: ^c_char,
optlen: ^c_int,
) -> c_int ---
}

View File

@@ -1,7 +1,10 @@
package all
import botan "vendor:botan"
import cgltf "vendor:cgltf"
// import commonmark "vendor:commonmark"
import ENet "vendor:ENet"
import exr "vendor:OpenEXRCore"
import ggpo "vendor:ggpo"
import gl "vendor:OpenGL"
import glfw "vendor:glfw"
@@ -9,8 +12,7 @@ import microui "vendor:microui"
import miniaudio "vendor:miniaudio"
import PM "vendor:portmidi"
import rl "vendor:raylib"
import exr "vendor:OpenEXRCore"
import cgltf "vendor:cgltf"
import zlib "vendor:zlib"
import SDL "vendor:sdl2"
import SDLNet "vendor:sdl2/net"
@@ -24,8 +26,14 @@ import NS "vendor:darwin/Foundation"
import MTL "vendor:darwin/Metal"
import CA "vendor:darwin/QuartzCore"
// NOTE(bill): only one can be checked at a time
import lua_5_4 "vendor:lua/5.4"
_ :: botan
_ :: cgltf
// _ :: commonmark
_ :: ENet
_ :: exr
_ :: ggpo
_ :: gl
_ :: glfw
@@ -33,8 +41,7 @@ _ :: microui
_ :: miniaudio
_ :: PM
_ :: rl
_ :: exr
_ :: cgltf
_ :: zlib
_ :: SDL
_ :: SDLNet
@@ -46,4 +53,6 @@ _ :: vk
_ :: NS
_ :: MTL
_ :: CA
_ :: CA
_ :: lua_5_4

View File

@@ -0,0 +1,56 @@
#!/bin/bash
OS=$(uname)
panic() {
printf "%s\n" "$1"
exit 1
}
assert_vendor() {
if [ $(basename $(pwd)) != 'vendor' ]; then
panic "Not in vendor directory!"
fi
}
remove_windows_libraries() {
find . -type f -name '*.dll' | xargs rm -f
find . -type f -name '*.lib' | xargs rm -f
find . -type d -name 'windows' | xargs rm -rf
}
remove_macos_libraries() {
find . -type f -name '*.dylib' | xargs rm -f
find . -type d -name '*macos*' | xargs rm -rf
}
remove_linux_libraries() {
find . -type f -name '*.so' | xargs rm -f
find . -type d -name 'linux' | xargs rm -rf
}
case $OS in
Linux)
assert_vendor
remove_windows_libraries
remove_macos_libraries
;;
Darwin)
assert_vendor
remove_windows_libraries
remove_linux_libraries
;;
OpenBSD)
assert_vendor
remove_windows_libraries
remove_macos_libraries
remove_linux_libraries
;;
FreeBSD)
assert_vendor
remove_windows_libraries
remove_macos_libraries
remove_linux_libraries
;;
*)
panic "Platform unsupported!"
esac

View File

@@ -7,6 +7,8 @@
// #define DEFAULT_TO_THREADED_CHECKER
// #endif
#define DEFAULT_MAX_ERROR_COLLECTOR_COUNT (36)
enum TargetOsKind : u16 {
TargetOs_Invalid,
@@ -313,6 +315,8 @@ struct BuildContext {
RelocMode reloc_mode;
bool disable_red_zone;
isize max_error_count;
u32 cmd_doc_flags;
Array<String> extra_packages;
@@ -344,6 +348,14 @@ gb_internal bool global_ignore_warnings(void) {
return build_context.ignore_warnings;
}
gb_internal isize MAX_ERROR_COLLECTOR_COUNT(void) {
if (build_context.max_error_count <= 0) {
return DEFAULT_MAX_ERROR_COLLECTOR_COUNT;
}
return build_context.max_error_count;
}
gb_global TargetMetrics target_windows_i386 = {
TargetOs_windows,
@@ -1081,6 +1093,10 @@ gb_internal void init_build_context(TargetMetrics *cross_target) {
bc->ODIN_VERSION = ODIN_VERSION;
bc->ODIN_ROOT = odin_root_dir();
if (bc->max_error_count <= 0) {
bc->max_error_count = DEFAULT_MAX_ERROR_COLLECTOR_COUNT;
}
{
char const *found = gb_get_env("ODIN_ERROR_POS_STYLE", permanent_allocator());
if (found) {

View File

@@ -131,6 +131,14 @@ gb_internal void check_init_variables(CheckerContext *ctx, Entity **lhs, isize l
if (d != nullptr) {
d->init_expr = o->expr;
}
if (o->type && is_type_no_copy(o->type)) {
begin_error_block();
if (check_no_copy_assignment(*o, str_lit("initialization"))) {
error_line("\tInitialization of a #no_copy type must be either implicitly zero, a constant literal, or a return value from a call expression");
}
end_error_block();
}
}
if (rhs_count > 0 && lhs_count != rhs_count) {
error(lhs[0]->token, "Assignment count mismatch '%td' = '%td'", lhs_count, rhs_count);

View File

@@ -1631,7 +1631,9 @@ gb_internal Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *nam
}
return e;
case Entity_LibraryName:
error(n, "Use of library '%.*s' not in foreign block", LIT(name));
if (!allow_import_name) {
error(n, "Use of library '%.*s' not in foreign block", LIT(name));
}
return e;
case Entity_Label:
@@ -5043,6 +5045,21 @@ gb_internal isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lh
return tuple_count;
}
gb_internal bool check_no_copy_assignment(Operand const &o, String const &context) {
if (o.type && is_type_no_copy(o.type)) {
Ast *expr = unparen_expr(o.expr);
if (expr && o.mode != Addressing_Constant) {
if (expr->kind == Ast_CallExpr) {
// Okay
} else {
error(o.expr, "Invalid use of #no_copy value in %.*s", LIT(context));
return true;
}
}
}
return false;
}
gb_internal bool check_assignment_arguments(CheckerContext *ctx, Array<Operand> const &lhs, Array<Operand> *operands, Slice<Ast *> const &rhs) {
bool optional_ok = false;
@@ -5114,6 +5131,7 @@ gb_internal bool check_assignment_arguments(CheckerContext *ctx, Array<Operand>
for (Entity *e : tuple->variables) {
o.type = e->type;
array_add(operands, o);
check_no_copy_assignment(o, str_lit("assignment"));
}
tuple_index += tuple->variables.count;
@@ -5952,6 +5970,10 @@ gb_internal CallArgumentData check_call_arguments(CheckerContext *c, Operand *op
}
}
for (Operand const &o : operands) {
check_no_copy_assignment(o, str_lit("call expression"));
}
if (operand->mode == Addressing_ProcGroup) {
check_entity_decl(c, operand->proc_group, nullptr, nullptr);

View File

@@ -326,7 +326,6 @@ gb_internal bool check_is_terminating(Ast *node, String const &label) {
gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs) {
if (rhs->mode == Addressing_Invalid) {
return nullptr;
@@ -339,6 +338,8 @@ gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, O
Ast *node = unparen_expr(lhs->expr);
check_no_copy_assignment(*rhs, str_lit("assignment"));
// NOTE(bill): Ignore assignments to '_'
if (is_blank_ident(node)) {
check_assignment(ctx, rhs, nullptr, str_lit("assignment to '_' identifier"));
@@ -400,6 +401,7 @@ gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, O
}
Type *assignment_type = lhs->type;
switch (lhs->mode) {
case Addressing_Invalid:
return nullptr;

View File

@@ -609,8 +609,9 @@ gb_internal void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *
context = str_lit("struct #raw_union");
}
struct_type->Struct.scope = ctx->scope;
struct_type->Struct.is_packed = st->is_packed;
struct_type->Struct.scope = ctx->scope;
struct_type->Struct.is_packed = st->is_packed;
struct_type->Struct.is_no_copy = st->is_no_copy;
struct_type->Struct.polymorphic_params = check_record_polymorphic_params(
ctx, st->polymorphic_params,
&struct_type->Struct.is_polymorphic,

View File

@@ -3081,6 +3081,54 @@ gb_internal DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
}
error(elem, "Expected a procedure entity for '%.*s'", LIT(name));
return false;
} else if (name == "deferred_in_by_ptr") {
if (value != nullptr) {
Operand o = {};
check_expr(c, &o, value);
Entity *e = entity_of_node(o.expr);
if (e != nullptr && e->kind == Entity_Procedure) {
if (ac->deferred_procedure.entity != nullptr) {
error(elem, "Previous usage of a 'deferred_*' attribute");
}
ac->deferred_procedure.kind = DeferredProcedure_in_by_ptr;
ac->deferred_procedure.entity = e;
return true;
}
}
error(elem, "Expected a procedure entity for '%.*s'", LIT(name));
return false;
} else if (name == "deferred_out_by_ptr") {
if (value != nullptr) {
Operand o = {};
check_expr(c, &o, value);
Entity *e = entity_of_node(o.expr);
if (e != nullptr && e->kind == Entity_Procedure) {
if (ac->deferred_procedure.entity != nullptr) {
error(elem, "Previous usage of a 'deferred_*' attribute");
}
ac->deferred_procedure.kind = DeferredProcedure_out_by_ptr;
ac->deferred_procedure.entity = e;
return true;
}
}
error(elem, "Expected a procedure entity for '%.*s'", LIT(name));
return false;
} else if (name == "deferred_in_out_by_ptr") {
if (value != nullptr) {
Operand o = {};
check_expr(c, &o, value);
Entity *e = entity_of_node(o.expr);
if (e != nullptr && e->kind == Entity_Procedure) {
if (ac->deferred_procedure.entity != nullptr) {
error(elem, "Previous usage of a 'deferred_*' attribute");
}
ac->deferred_procedure.kind = DeferredProcedure_in_out_by_ptr;
ac->deferred_procedure.entity = e;
return true;
}
}
error(elem, "Expected a procedure entity for '%.*s'", LIT(name));
return false;
} else if (name == "link_name") {
ExactValue ev = check_decl_attribute_value(c, value);
@@ -5438,6 +5486,26 @@ gb_internal void add_untyped_expressions(CheckerInfo *cinfo, UntypedExprInfoMap
map_clear(untyped);
}
gb_internal Type *tuple_to_pointers(Type *ot) {
if (ot == nullptr) {
return nullptr;
}
GB_ASSERT(ot->kind == Type_Tuple);
Type *t = alloc_type_tuple();
t->Tuple.variables = slice_make<Entity *>(heap_allocator(), ot->Tuple.variables.count);
Scope *scope = nullptr;
for_array(i, t->Tuple.variables) {
Entity *e = ot->Tuple.variables[i];
t->Tuple.variables[i] = alloc_entity_variable(scope, e->token, alloc_type_pointer(e->type));
}
t->Tuple.is_packed = ot->Tuple.is_packed;
return t;
}
gb_internal void check_deferred_procedures(Checker *c) {
for (Entity *src = nullptr; mpsc_dequeue(&c->procs_with_deferred_to_check, &src); /**/) {
GB_ASSERT(src->kind == Entity_Procedure);
@@ -5449,18 +5517,13 @@ gb_internal void check_deferred_procedures(Checker *c) {
char const *attribute = "deferred_none";
switch (dst_kind) {
case DeferredProcedure_none:
attribute = "deferred_none";
break;
case DeferredProcedure_in:
attribute = "deferred_in";
break;
case DeferredProcedure_out:
attribute = "deferred_out";
break;
case DeferredProcedure_in_out:
attribute = "deferred_in_out";
break;
case DeferredProcedure_none: attribute = "deferred_none"; break;
case DeferredProcedure_in: attribute = "deferred_in"; break;
case DeferredProcedure_out: attribute = "deferred_out"; break;
case DeferredProcedure_in_out: attribute = "deferred_in_out"; break;
case DeferredProcedure_in_by_ptr: attribute = "deferred_in_by_ptr"; break;
case DeferredProcedure_out_by_ptr: attribute = "deferred_out_by_ptr"; break;
case DeferredProcedure_in_out_by_ptr: attribute = "deferred_in_out_by_ptr"; break;
}
if (is_type_polymorphic(src->type) || is_type_polymorphic(dst->type)) {
@@ -5474,118 +5537,146 @@ gb_internal void check_deferred_procedures(Checker *c) {
Type *src_results = base_type(src->type)->Proc.results;
Type *dst_params = base_type(dst->type)->Proc.params;
if (dst_kind == DeferredProcedure_none) {
if (dst_params == nullptr) {
// Okay
continue;
}
bool by_ptr = false;
switch (dst_kind) {
case DeferredProcedure_in_by_ptr:
by_ptr = true;
src_params = tuple_to_pointers(src_params);
break;
case DeferredProcedure_out_by_ptr:
by_ptr = true;
src_results = tuple_to_pointers(src_results);
break;
case DeferredProcedure_in_out_by_ptr:
by_ptr = true;
src_params = tuple_to_pointers(src_params);
src_results = tuple_to_pointers(src_results);
break;
}
error(src->token, "Deferred procedure '%.*s' must have no input parameters", LIT(dst->token.string));
} else if (dst_kind == DeferredProcedure_in) {
if (src_params == nullptr && dst_params == nullptr) {
// Okay
continue;
}
if ((src_params == nullptr && dst_params != nullptr) ||
(src_params != nullptr && dst_params == nullptr)) {
error(src->token, "Deferred procedure '%.*s' parameters do not match the inputs of initial procedure '%.*s'", LIT(src->token.string), LIT(dst->token.string));
continue;
}
switch (dst_kind) {
case DeferredProcedure_none:
{
if (dst_params == nullptr) {
// Okay
continue;
}
GB_ASSERT(src_params->kind == Type_Tuple);
GB_ASSERT(dst_params->kind == Type_Tuple);
error(src->token, "Deferred procedure '%.*s' must have no input parameters", LIT(dst->token.string));
} break;
case DeferredProcedure_in:
case DeferredProcedure_in_by_ptr:
{
if (src_params == nullptr && dst_params == nullptr) {
// Okay
continue;
}
if ((src_params == nullptr && dst_params != nullptr) ||
(src_params != nullptr && dst_params == nullptr)) {
error(src->token, "Deferred procedure '%.*s' parameters do not match the inputs of initial procedure '%.*s'", LIT(src->token.string), LIT(dst->token.string));
continue;
}
if (are_types_identical(src_params, dst_params)) {
// Okay!
} else {
gbString s = type_to_string(src_params);
gbString d = type_to_string(dst_params);
error(src->token, "Deferred procedure '%.*s' parameters do not match the inputs of initial procedure '%.*s':\n\t(%s) =/= (%s)",
LIT(src->token.string), LIT(dst->token.string),
s, d
);
gb_string_free(d);
gb_string_free(s);
continue;
}
} else if (dst_kind == DeferredProcedure_out) {
if (src_results == nullptr && dst_params == nullptr) {
// Okay
continue;
}
if ((src_results == nullptr && dst_params != nullptr) ||
(src_results != nullptr && dst_params == nullptr)) {
error(src->token, "Deferred procedure '%.*s' parameters do not match the results of initial procedure '%.*s'", LIT(src->token.string), LIT(dst->token.string));
continue;
}
GB_ASSERT(src_results->kind == Type_Tuple);
GB_ASSERT(dst_params->kind == Type_Tuple);
if (are_types_identical(src_results, dst_params)) {
// Okay!
} else {
gbString s = type_to_string(src_results);
gbString d = type_to_string(dst_params);
error(src->token, "Deferred procedure '%.*s' parameters do not match the results of initial procedure '%.*s':\n\t(%s) =/= (%s)",
LIT(src->token.string), LIT(dst->token.string),
s, d
);
gb_string_free(d);
gb_string_free(s);
continue;
}
} else if (dst_kind == DeferredProcedure_in_out) {
if (src_params == nullptr && src_results == nullptr && dst_params == nullptr) {
// Okay
continue;
}
GB_ASSERT(dst_params->kind == Type_Tuple);
Type *tsrc = alloc_type_tuple();
auto &sv = tsrc->Tuple.variables;
auto const &dv = dst_params->Tuple.variables;
gb_unused(dv);
isize len = 0;
if (src_params != nullptr) {
GB_ASSERT(src_params->kind == Type_Tuple);
len += src_params->Tuple.variables.count;
}
if (src_results != nullptr) {
GB_ASSERT(dst_params->kind == Type_Tuple);
if (are_types_identical(src_params, dst_params)) {
// Okay!
} else {
gbString s = type_to_string(src_params);
gbString d = type_to_string(dst_params);
error(src->token, "Deferred procedure '%.*s' parameters do not match the inputs of initial procedure '%.*s':\n\t(%s) =/= (%s)",
LIT(src->token.string), LIT(dst->token.string),
s, d
);
gb_string_free(d);
gb_string_free(s);
continue;
}
} break;
case DeferredProcedure_out:
case DeferredProcedure_out_by_ptr:
{
if (src_results == nullptr && dst_params == nullptr) {
// Okay
continue;
}
if ((src_results == nullptr && dst_params != nullptr) ||
(src_results != nullptr && dst_params == nullptr)) {
error(src->token, "Deferred procedure '%.*s' parameters do not match the results of initial procedure '%.*s'", LIT(src->token.string), LIT(dst->token.string));
continue;
}
GB_ASSERT(src_results->kind == Type_Tuple);
len += src_results->Tuple.variables.count;
}
slice_init(&sv, heap_allocator(), len);
isize offset = 0;
if (src_params != nullptr) {
for_array(i, src_params->Tuple.variables) {
sv[offset++] = src_params->Tuple.variables[i];
GB_ASSERT(dst_params->kind == Type_Tuple);
if (are_types_identical(src_results, dst_params)) {
// Okay!
} else {
gbString s = type_to_string(src_results);
gbString d = type_to_string(dst_params);
error(src->token, "Deferred procedure '%.*s' parameters do not match the results of initial procedure '%.*s':\n\t(%s) =/= (%s)",
LIT(src->token.string), LIT(dst->token.string),
s, d
);
gb_string_free(d);
gb_string_free(s);
continue;
}
}
if (src_results != nullptr) {
for_array(i, src_results->Tuple.variables) {
sv[offset++] = src_results->Tuple.variables[i];
} break;
case DeferredProcedure_in_out:
case DeferredProcedure_in_out_by_ptr:
{
if (src_params == nullptr && src_results == nullptr && dst_params == nullptr) {
// Okay
continue;
}
}
GB_ASSERT(offset == len);
GB_ASSERT(dst_params->kind == Type_Tuple);
Type *tsrc = alloc_type_tuple();
auto &sv = tsrc->Tuple.variables;
auto const &dv = dst_params->Tuple.variables;
gb_unused(dv);
isize len = 0;
if (src_params != nullptr) {
GB_ASSERT(src_params->kind == Type_Tuple);
len += src_params->Tuple.variables.count;
}
if (src_results != nullptr) {
GB_ASSERT(src_results->kind == Type_Tuple);
len += src_results->Tuple.variables.count;
}
slice_init(&sv, heap_allocator(), len);
isize offset = 0;
if (src_params != nullptr) {
for_array(i, src_params->Tuple.variables) {
sv[offset++] = src_params->Tuple.variables[i];
}
}
if (src_results != nullptr) {
for_array(i, src_results->Tuple.variables) {
sv[offset++] = src_results->Tuple.variables[i];
}
}
GB_ASSERT(offset == len);
if (are_types_identical(tsrc, dst_params)) {
// Okay!
} else {
gbString s = type_to_string(tsrc);
gbString d = type_to_string(dst_params);
error(src->token, "Deferred procedure '%.*s' parameters do not match the results of initial procedure '%.*s':\n\t(%s) =/= (%s)",
LIT(src->token.string), LIT(dst->token.string),
s, d
);
gb_string_free(d);
gb_string_free(s);
continue;
}
if (are_types_identical(tsrc, dst_params)) {
// Okay!
} else {
gbString s = type_to_string(tsrc);
gbString d = type_to_string(dst_params);
error(src->token, "Deferred procedure '%.*s' parameters do not match the results of initial procedure '%.*s':\n\t(%s) =/= (%s)",
LIT(src->token.string), LIT(dst->token.string),
s, d
);
gb_string_free(d);
gb_string_free(s);
continue;
}
} break;
}
}

View File

@@ -92,6 +92,10 @@ enum DeferredProcedureKind {
DeferredProcedure_in,
DeferredProcedure_out,
DeferredProcedure_in_out,
DeferredProcedure_in_by_ptr,
DeferredProcedure_out_by_ptr,
DeferredProcedure_in_out_by_ptr,
};
struct DeferredProcedure {
DeferredProcedureKind kind;

View File

@@ -14,8 +14,6 @@ struct ErrorCollector {
gb_global ErrorCollector global_error_collector;
#define MAX_ERROR_COLLECTOR_COUNT (36)
gb_internal bool any_errors(void) {
return global_error_collector.count.load() != 0;
@@ -28,6 +26,8 @@ gb_internal void init_global_error_collector(void) {
array_init(&global_files, heap_allocator(), 1, 4096);
}
gb_internal isize MAX_ERROR_COLLECTOR_COUNT(void);
// temporary
// defined in build_settings.cpp
@@ -356,7 +356,7 @@ gb_internal void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va
show_error_on_line(pos, end);
}
mutex_unlock(&global_error_collector.mutex);
if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT) {
if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT()) {
gb_exit(1);
}
}
@@ -407,7 +407,7 @@ gb_internal void error_no_newline_va(TokenPos const &pos, char const *fmt, va_li
error_out_va(fmt, va);
}
mutex_unlock(&global_error_collector.mutex);
if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT) {
if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT()) {
gb_exit(1);
}
}
@@ -431,7 +431,7 @@ gb_internal void syntax_error_va(TokenPos const &pos, TokenPos end, char const *
}
mutex_unlock(&global_error_collector.mutex);
if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT) {
if (global_error_collector.count > MAX_ERROR_COLLECTOR_COUNT()) {
gb_exit(1);
}
}

View File

@@ -462,6 +462,8 @@ gb_internal lbValue lb_hasher_proc_for_type(lbModule *m, Type *type) {
}
#define LLVM_SET_VALUE_NAME(value, name) LLVMSetValueName2((value), (name), gb_count_of((name))-1);
gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
GB_ASSERT(!build_context.dynamic_map_calls);
type = base_type(type);
@@ -486,7 +488,6 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
defer (lb_end_procedure_body(p));
LLVMSetLinkage(p->value, LLVMInternalLinkage);
// lb_add_attribute_to_proc(m, p->value, "readonly");
lb_add_attribute_to_proc(m, p->value, "nounwind");
// if (build_context.ODIN_DEBUG) {
lb_add_attribute_to_proc(m, p->value, "noinline");
@@ -499,45 +500,56 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
lbValue h = {y, t_uintptr};
lbValue key_ptr = {z, t_rawptr};
LLVM_SET_VALUE_NAME(h.value, "hash");
lb_add_proc_attribute_at_index(p, 1+0, "nonnull");
lb_add_proc_attribute_at_index(p, 1+0, "noalias");
lb_add_proc_attribute_at_index(p, 1+0, "readonly");
lb_add_proc_attribute_at_index(p, 1+2, "nonnull");
lb_add_proc_attribute_at_index(p, 1+2, "noalias");
lb_add_proc_attribute_at_index(p, 1+2, "readonly");
lbBlock *loop_block = lb_create_block(p, "loop");
lbBlock *hash_block = lb_create_block(p, "hash");
lbBlock *probe_block = lb_create_block(p, "probe");
lbBlock *increment_block = lb_create_block(p, "increment");
lbBlock *loop_block = lb_create_block(p, "loop");
lbBlock *hash_block = lb_create_block(p, "hash");
lbBlock *probe_block = lb_create_block(p, "probe");
lbBlock *increment_block = lb_create_block(p, "increment");
lbBlock *hash_compare_block = lb_create_block(p, "hash_compare");
lbBlock *key_compare_block = lb_create_block(p, "key_compare");
lbBlock *value_block = lb_create_block(p, "value");
lbBlock *nil_block = lb_create_block(p, "nil");
lbBlock *key_compare_block = lb_create_block(p, "key_compare");
lbBlock *value_block = lb_create_block(p, "value");
lbBlock *nil_block = lb_create_block(p, "nil");
map_ptr = lb_emit_conv(p, map_ptr, t_raw_map_ptr);
LLVM_SET_VALUE_NAME(map_ptr.value, "map_ptr");
lbValue map = lb_emit_load(p, map_ptr);
LLVM_SET_VALUE_NAME(map.value, "map");
lbValue length = lb_map_len(p, map);
LLVM_SET_VALUE_NAME(length.value, "length");
lb_emit_if(p, lb_emit_comp(p, Token_CmpEq, length, lb_const_nil(m, t_int)), nil_block, hash_block);
lb_start_block(p, hash_block);
key_ptr = lb_emit_conv(p, key_ptr, alloc_type_pointer(type->Map.key));
LLVM_SET_VALUE_NAME(key_ptr.value, "key_ptr");
lbValue key = lb_emit_load(p, key_ptr);
LLVM_SET_VALUE_NAME(key.value, "key");
lbAddr pos = lb_add_local_generated(p, t_uintptr, false);
lbAddr distance = lb_add_local_generated(p, t_uintptr, true);
LLVM_SET_VALUE_NAME(pos.addr.value, "pos");
LLVM_SET_VALUE_NAME(distance.addr.value, "distance");
lbValue capacity = lb_map_cap(p, map);
lbValue mask = lb_emit_conv(p, lb_emit_arith(p, Token_Sub, capacity, lb_const_int(m, t_int, 1), t_int), t_uintptr);
LLVM_SET_VALUE_NAME(capacity.value, "capacity");
lbValue cap_minus_1 = lb_emit_arith(p, Token_Sub, capacity, lb_const_int(m, t_int, 1), t_int);
lbValue mask = lb_emit_conv(p, cap_minus_1, t_uintptr);
LLVM_SET_VALUE_NAME(mask.value, "mask");
{
TEMPORARY_ALLOCATOR_GUARD();
auto args = array_make<lbValue>(temporary_allocator(), 2);
args[0] = map;
args[1] = h;
lb_addr_store(p, pos, lb_emit_runtime_call(p, "map_desired_position", args));
// map_desired_position inlined
lbValue the_pos = lb_emit_arith(p, Token_And, h, mask, t_uintptr);
the_pos = lb_emit_conv(p, the_pos, t_uintptr);
lb_addr_store(p, pos, the_pos);
}
lbValue zero_uintptr = lb_const_int(m, t_uintptr, 0);
lbValue one_uintptr = lb_const_int(m, t_uintptr, 1);
@@ -550,10 +562,16 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
vs = lb_emit_conv(p, vs, alloc_type_pointer(type->Map.value));
hs = lb_emit_conv(p, hs, alloc_type_pointer(t_uintptr));
LLVM_SET_VALUE_NAME(ks.value, "ks");
LLVM_SET_VALUE_NAME(vs.value, "vs");
LLVM_SET_VALUE_NAME(hs.value, "hs");
lb_emit_jump(p, loop_block);
lb_start_block(p, loop_block);
lbValue element_hash = lb_emit_load(p, lb_emit_ptr_offset(p, hs, lb_addr_load(p, pos)));
LLVM_SET_VALUE_NAME(element_hash.value, "element_hash");
{
// if element_hash == 0 { return nil }
lb_emit_if(p, lb_emit_comp(p, Token_CmpEq, element_hash, zero_uintptr), nil_block, probe_block);
@@ -561,12 +579,16 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
lb_start_block(p, probe_block);
{
TEMPORARY_ALLOCATOR_GUARD();
auto args = array_make<lbValue>(temporary_allocator(), 3);
args[0] = map;
args[1] = element_hash;
args[2] = lb_addr_load(p, pos);
lbValue probe_distance = lb_emit_runtime_call(p, "map_probe_distance", args);
// map_probe_distance inlined
lbValue probe_distance = lb_emit_arith(p, Token_And, h, mask, t_uintptr);
probe_distance = lb_emit_conv(p, probe_distance, t_uintptr);
lbValue cap = lb_emit_conv(p, capacity, t_uintptr);
lbValue base = lb_emit_arith(p, Token_Add, lb_addr_load(p, pos), cap, t_uintptr);
probe_distance = lb_emit_arith(p, Token_Sub, base, probe_distance, t_uintptr);
probe_distance = lb_emit_arith(p, Token_And, probe_distance, mask, t_uintptr);
LLVM_SET_VALUE_NAME(probe_distance.value, "probe_distance");
lbValue cond = lb_emit_comp(p, Token_Gt, lb_addr_load(p, distance), probe_distance);
lb_emit_if(p, cond, nil_block, hash_compare_block);
}
@@ -580,6 +602,8 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
{
lbValue element_key = lb_map_cell_index_static(p, type->Map.key, ks, lb_addr_load(p, pos));
element_key = lb_emit_conv(p, element_key, ks.type);
LLVM_SET_VALUE_NAME(element_key.value, "element_key_ptr");
lbValue cond = lb_emit_comp(p, Token_CmpEq, lb_emit_load(p, element_key), key);
lb_emit_if(p, cond, value_block, increment_block);
}
@@ -587,6 +611,7 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
lb_start_block(p, value_block);
{
lbValue element_value = lb_map_cell_index_static(p, type->Map.value, vs, lb_addr_load(p, pos));
LLVM_SET_VALUE_NAME(element_value.value, "element_value_ptr");
element_value = lb_emit_conv(p, element_value, t_rawptr);
LLVMBuildRet(p->builder, element_value.value);
}
@@ -607,8 +632,7 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
LLVMBuildRet(p->builder, res.value);
}
gb_printf_err("%s\n", LLVMPrintValueToString(p->value));
// gb_printf_err("%s\n", LLVMPrintValueToString(p->value));
return {p->value, p->type};
}
@@ -1351,24 +1375,28 @@ gb_internal WORKER_TASK_PROC(lb_llvm_function_pass_per_module) {
m->function_pass_managers[lbFunctionPassManager_default] = LLVMCreateFunctionPassManagerForModule(m->mod);
m->function_pass_managers[lbFunctionPassManager_default_without_memcpy] = LLVMCreateFunctionPassManagerForModule(m->mod);
m->function_pass_managers[lbFunctionPassManager_none] = LLVMCreateFunctionPassManagerForModule(m->mod);
m->function_pass_managers[lbFunctionPassManager_minimal] = LLVMCreateFunctionPassManagerForModule(m->mod);
m->function_pass_managers[lbFunctionPassManager_size] = LLVMCreateFunctionPassManagerForModule(m->mod);
m->function_pass_managers[lbFunctionPassManager_speed] = LLVMCreateFunctionPassManagerForModule(m->mod);
LLVMInitializeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_default]);
LLVMInitializeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_default_without_memcpy]);
LLVMInitializeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_none]);
LLVMInitializeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_minimal]);
LLVMInitializeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_size]);
LLVMInitializeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_speed]);
lb_populate_function_pass_manager(m, m->function_pass_managers[lbFunctionPassManager_default], false, build_context.optimization_level);
lb_populate_function_pass_manager(m, m->function_pass_managers[lbFunctionPassManager_default_without_memcpy], true, build_context.optimization_level);
lb_populate_function_pass_manager_specific(m, m->function_pass_managers[lbFunctionPassManager_none], -1);
lb_populate_function_pass_manager_specific(m, m->function_pass_managers[lbFunctionPassManager_minimal], 0);
lb_populate_function_pass_manager_specific(m, m->function_pass_managers[lbFunctionPassManager_size], 1);
lb_populate_function_pass_manager_specific(m, m->function_pass_managers[lbFunctionPassManager_speed], 2);
LLVMFinalizeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_default]);
LLVMFinalizeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_default_without_memcpy]);
LLVMFinalizeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_none]);
LLVMFinalizeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_minimal]);
LLVMFinalizeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_size]);
LLVMFinalizeFunctionPassManager(m->function_pass_managers[lbFunctionPassManager_speed]);
@@ -1417,11 +1445,11 @@ gb_internal WORKER_TASK_PROC(lb_llvm_function_pass_per_module) {
}
for (auto const &entry : m->map_get_procs) {
lbProcedure *p = entry.value;
lb_llvm_function_pass_per_function_internal(m, p);
lb_llvm_function_pass_per_function_internal(m, p, lbFunctionPassManager_none);
}
for (auto const &entry : m->map_set_procs) {
lbProcedure *p = entry.value;
lb_llvm_function_pass_per_function_internal(m, p);
lb_llvm_function_pass_per_function_internal(m, p, lbFunctionPassManager_none);
}
return 0;

View File

@@ -120,6 +120,7 @@ typedef Slice<i32> lbStructFieldRemapping;
enum lbFunctionPassManagerKind {
lbFunctionPassManager_default,
lbFunctionPassManager_default_without_memcpy,
lbFunctionPassManager_none,
lbFunctionPassManager_minimal,
lbFunctionPassManager_size,
lbFunctionPassManager_speed,
@@ -138,9 +139,11 @@ struct lbModule {
AstPackage *pkg; // possibly associated
AstFile *file; // possibly associated
PtrMap<Type *, LLVMTypeRef> types;
PtrMap<Type *, LLVMTypeRef> func_raw_types;
PtrMap<void *, lbStructFieldRemapping> struct_field_remapping; // Key: LLVMTypeRef or Type *
PtrMap<Type *, LLVMTypeRef> types; // mutex: types_mutex
PtrMap<void *, lbStructFieldRemapping> struct_field_remapping; // Key: LLVMTypeRef or Type *, mutex: types_mutex
PtrMap<Type *, LLVMTypeRef> func_raw_types; // mutex: func_raw_types_mutex
RecursiveMutex types_mutex;
RecursiveMutex func_raw_types_mutex;
i32 internal_type_level;
RwMutex values_mutex;

View File

@@ -1498,6 +1498,9 @@ gb_internal LLVMTypeRef lb_type_internal_for_procedures_raw(lbModule *m, Type *t
type = base_type(original_type);
GB_ASSERT(type->kind == Type_Proc);
mutex_lock(&m->func_raw_types_mutex);
defer (mutex_unlock(&m->func_raw_types_mutex));
LLVMTypeRef *found = map_get(&m->func_raw_types, type);
if (found) {
return *found;
@@ -2157,6 +2160,9 @@ gb_internal LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
gb_internal LLVMTypeRef lb_type(lbModule *m, Type *type) {
type = default_type(type);
mutex_lock(&m->types_mutex);
defer (mutex_unlock(&m->types_mutex));
LLVMTypeRef *found = map_get(&m->types, type);
if (found) {
return *found;

View File

@@ -1169,17 +1169,27 @@ gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> c
lbValue deferred = lb_find_procedure_value_from_entity(p->module, deferred_entity);
bool by_ptr = false;
auto in_args = args;
Array<lbValue> result_as_args = {};
switch (kind) {
case DeferredProcedure_none:
break;
case DeferredProcedure_in_by_ptr:
by_ptr = true;
/*fallthrough*/
case DeferredProcedure_in:
result_as_args = array_clone(heap_allocator(), in_args);
break;
case DeferredProcedure_out_by_ptr:
by_ptr = true;
/*fallthrough*/
case DeferredProcedure_out:
result_as_args = lb_value_to_array(p, heap_allocator(), result);
break;
case DeferredProcedure_in_out_by_ptr:
by_ptr = true;
/*fallthrough*/
case DeferredProcedure_in_out:
{
auto out_args = lb_value_to_array(p, heap_allocator(), result);
@@ -1189,6 +1199,12 @@ gb_internal lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> c
}
break;
}
if (by_ptr) {
for_array(i, result_as_args) {
lbValue arg_ptr = lb_address_from_load_or_generate_local(p, result_as_args[i]);
result_as_args[i] = arg_ptr;
}
}
lb_add_defer_proc(p, p->scope_index, deferred, result_as_args);
}
@@ -2042,7 +2058,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
i64 al = exact_value_to_i64(type_and_value_of_expr(ce->args[1]).value);
lbValue res = {};
res.type = t_u8_ptr;
res.type = alloc_type_multi_pointer(t_u8);
res.value = LLVMBuildArrayAlloca(p->builder, lb_type(p->module, t_u8), sz.value, "");
LLVMSetAlignment(res.value, cast(unsigned)al);
return res;
@@ -2363,9 +2379,15 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
{
lbValue dst = lb_build_expr(p, ce->args[0]);
lbValue src = lb_build_expr(p, ce->args[1]);
src = lb_address_from_load_or_generate_local(p, src);
Type *t = type_deref(dst.type);
lb_mem_copy_non_overlapping(p, dst, src, lb_const_int(p->module, t_int, type_size_of(t)), false);
if (is_type_simd_vector(t)) {
LLVMValueRef store = LLVMBuildStore(p->builder, src.value, dst.value);
LLVMSetAlignment(store, 1);
} else {
src = lb_address_from_load_or_generate_local(p, src);
lb_mem_copy_non_overlapping(p, dst, src, lb_const_int(p->module, t_int, type_size_of(t)), false);
}
return {};
}
@@ -2373,9 +2395,17 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
{
lbValue src = lb_build_expr(p, ce->args[0]);
Type *t = type_deref(src.type);
lbAddr dst = lb_add_local_generated(p, t, false);
lb_mem_copy_non_overlapping(p, dst.addr, src, lb_const_int(p->module, t_int, type_size_of(t)), false);
return lb_addr_load(p, dst);
if (is_type_simd_vector(t)) {
lbValue res = {};
res.type = t;
res.value = LLVMBuildLoad2(p->builder, lb_type(p->module, t), src.value, "");
LLVMSetAlignment(res.value, 1);
return res;
} else {
lbAddr dst = lb_add_local_generated(p, t, false);
lb_mem_copy_non_overlapping(p, dst.addr, src, lb_const_int(p->module, t_int, type_size_of(t)), false);
return lb_addr_load(p, dst);
}
}
case BuiltinProc_atomic_add:

View File

@@ -691,32 +691,34 @@ gb_internal void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup
case Type_Struct: {
tag = lb_const_ptr_cast(m, variant_ptr, t_type_info_struct_ptr);
LLVMValueRef vals[12] = {};
LLVMValueRef vals[13] = {};
{
lbValue is_packed = lb_const_bool(m, t_bool, t->Struct.is_packed);
lbValue is_raw_union = lb_const_bool(m, t_bool, t->Struct.is_raw_union);
lbValue is_no_copy = lb_const_bool(m, t_bool, t->Struct.is_no_copy);
lbValue is_custom_align = lb_const_bool(m, t_bool, t->Struct.custom_align != 0);
vals[5] = is_packed.value;
vals[6] = is_raw_union.value;
vals[7] = is_custom_align.value;
vals[7] = is_no_copy.value;
vals[8] = is_custom_align.value;
if (is_type_comparable(t) && !is_type_simple_compare(t)) {
vals[8] = lb_equal_proc_for_type(m, t).value;
vals[9] = lb_equal_proc_for_type(m, t).value;
}
if (t->Struct.soa_kind != StructSoa_None) {
lbValue kind = lb_emit_struct_ep(p, tag, 9);
lbValue kind = lb_emit_struct_ep(p, tag, 10);
Type *kind_type = type_deref(kind.type);
lbValue soa_kind = lb_const_value(m, kind_type, exact_value_i64(t->Struct.soa_kind));
lbValue soa_type = lb_type_info(m, t->Struct.soa_elem);
lbValue soa_len = lb_const_int(m, t_int, t->Struct.soa_count);
vals[9] = soa_kind.value;
vals[10] = soa_type.value;
vals[11] = soa_len.value;
vals[10] = soa_kind.value;
vals[11] = soa_type.value;
vals[12] = soa_len.value;
}
}

View File

@@ -910,11 +910,18 @@ gb_internal lbValue lb_address_from_load_if_readonly_parameter(lbProcedure *p, l
gb_internal lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t) {
t = base_type(t);
LLVMTypeRef struct_type = lb_type(m, t);
mutex_lock(&m->types_mutex);
auto *field_remapping = map_get(&m->struct_field_remapping, cast(void *)struct_type);
if (field_remapping == nullptr) {
field_remapping = map_get(&m->struct_field_remapping, cast(void *)t);
}
mutex_unlock(&m->types_mutex);
GB_ASSERT_MSG(field_remapping != nullptr, "%s", type_to_string(t));
return *field_remapping;
}

View File

@@ -691,6 +691,7 @@ enum BuildFlagKind {
BuildFlag_TerseErrors,
BuildFlag_VerboseErrors,
BuildFlag_ErrorPosStyle,
BuildFlag_MaxErrorCount,
// internal use only
BuildFlag_InternalIgnoreLazy,
@@ -866,6 +867,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
add_flag(&build_flags, BuildFlag_TerseErrors, str_lit("terse-errors"), BuildFlagParam_None, Command_all);
add_flag(&build_flags, BuildFlag_VerboseErrors, str_lit("verbose-errors"), BuildFlagParam_None, Command_all);
add_flag(&build_flags, BuildFlag_ErrorPosStyle, str_lit("error-pos-style"), BuildFlagParam_String, Command_all);
add_flag(&build_flags, BuildFlag_MaxErrorCount, str_lit("max-error-count"), BuildFlagParam_Integer, Command_all);
add_flag(&build_flags, BuildFlag_InternalIgnoreLazy, str_lit("internal-ignore-lazy"), BuildFlagParam_None, Command_all);
add_flag(&build_flags, BuildFlag_InternalIgnoreLLVMBuild, str_lit("internal-ignore-llvm-build"),BuildFlagParam_None, Command_all);
@@ -1522,6 +1524,17 @@ gb_internal bool parse_build_flags(Array<String> args) {
}
break;
case BuildFlag_MaxErrorCount: {
i64 count = big_int_to_i64(&value.value_integer);
if (count <= 0) {
gb_printf_err("-%.*s must be greater than 0", LIT(bf.name));
bad_flags = true;
} else {
build_context.max_error_count = cast(isize)count;
}
break;
}
case BuildFlag_InternalIgnoreLazy:
build_context.ignore_lazy = true;
break;
@@ -2212,8 +2225,21 @@ gb_internal void print_show_help(String const arg0, String const &command) {
print_usage_line(2, "Treats warning messages as error messages");
print_usage_line(0, "");
print_usage_line(1, "-verbose-errors");
print_usage_line(2, "Prints verbose error messages showing the code on that line and the location in that line");
print_usage_line(1, "-terse-errors");
print_usage_line(2, "Prints a terse error message without showing the code on that line and the location in that line");
print_usage_line(0, "");
print_usage_line(1, "-error-pos-style:<string>");
print_usage_line(2, "Options are 'unix', 'odin' and 'default' (odin)");
print_usage_line(2, "'odin' file/path(45:3)");
print_usage_line(2, "'unix' file/path:45:3:");
print_usage_line(0, "");
print_usage_line(1, "-max-error-count:<integer>");
print_usage_line(2, "Set the maximum number of errors that can be displayed before the compiler terminates");
print_usage_line(2, "Must be an integer >0");
print_usage_line(2, "If not set, the default max error count is %d", DEFAULT_MAX_ERROR_COLLECTOR_COUNT);
print_usage_line(0, "");
print_usage_line(1, "-foreign-error-procedures");

View File

@@ -1047,7 +1047,7 @@ gb_internal Ast *ast_dynamic_array_type(AstFile *f, Token token, Ast *elem) {
}
gb_internal Ast *ast_struct_type(AstFile *f, Token token, Slice<Ast *> fields, isize field_count,
Ast *polymorphic_params, bool is_packed, bool is_raw_union,
Ast *polymorphic_params, bool is_packed, bool is_raw_union, bool is_no_copy,
Ast *align,
Token where_token, Array<Ast *> const &where_clauses) {
Ast *result = alloc_ast_node(f, Ast_StructType);
@@ -1057,6 +1057,7 @@ gb_internal Ast *ast_struct_type(AstFile *f, Token token, Slice<Ast *> fields, i
result->StructType.polymorphic_params = polymorphic_params;
result->StructType.is_packed = is_packed;
result->StructType.is_raw_union = is_raw_union;
result->StructType.is_no_copy = is_no_copy;
result->StructType.align = align;
result->StructType.where_token = where_token;
result->StructType.where_clauses = slice_from_array(where_clauses);
@@ -2392,6 +2393,7 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
Ast *polymorphic_params = nullptr;
bool is_packed = false;
bool is_raw_union = false;
bool no_copy = false;
Ast *align = nullptr;
if (allow_token(f, Token_OpenParen)) {
@@ -2427,6 +2429,11 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
}
is_raw_union = true;
} else if (tag.string == "no_copy") {
if (is_packed) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
}
no_copy = true;
} else {
syntax_error(tag, "Invalid struct tag '#%.*s'", LIT(tag.string));
}
@@ -2465,7 +2472,7 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
decls = fields->FieldList.list;
}
return ast_struct_type(f, token, decls, name_count, polymorphic_params, is_packed, is_raw_union, align, where_token, where_clauses);
return ast_struct_type(f, token, decls, name_count, polymorphic_params, is_packed, is_raw_union, no_copy, align, where_token, where_clauses);
} break;
case Token_union: {

View File

@@ -693,6 +693,7 @@ AST_KIND(_TypeBegin, "", bool) \
Slice<Ast *> where_clauses; \
bool is_packed; \
bool is_raw_union; \
bool is_no_copy; \
}) \
AST_KIND(UnionType, "union type", struct { \
Scope *scope; \

View File

@@ -149,6 +149,7 @@ struct TypeStruct {
bool are_offsets_being_processed : 1;
bool is_packed : 1;
bool is_raw_union : 1;
bool is_no_copy : 1;
bool is_poly_specialized : 1;
};
@@ -1670,6 +1671,10 @@ gb_internal bool is_type_raw_union(Type *t) {
t = base_type(t);
return (t->kind == Type_Struct && t->Struct.is_raw_union);
}
gb_internal bool is_type_no_copy(Type *t) {
t = base_type(t);
return (t->kind == Type_Struct && t->Struct.is_no_copy);
}
gb_internal bool is_type_enum(Type *t) {
t = base_type(t);
return (t->kind == Type_Enum);
@@ -2655,6 +2660,7 @@ gb_internal bool are_types_identical_internal(Type *x, Type *y, bool check_tuple
case Type_Struct:
if (x->Struct.is_raw_union == y->Struct.is_raw_union &&
x->Struct.is_no_copy == y->Struct.is_no_copy &&
x->Struct.fields.count == y->Struct.fields.count &&
x->Struct.is_packed == y->Struct.is_packed &&
x->Struct.custom_align == y->Struct.custom_align &&
@@ -2683,7 +2689,7 @@ gb_internal bool are_types_identical_internal(Type *x, Type *y, bool check_tuple
return false;
}
}
return true;
return are_types_identical(x->Struct.polymorphic_params, y->Struct.polymorphic_params);
}
break;
@@ -4207,6 +4213,7 @@ gb_internal gbString write_type_to_string(gbString str, Type *type, bool shortha
str = gb_string_appendc(str, "struct");
if (type->Struct.is_packed) str = gb_string_appendc(str, " #packed");
if (type->Struct.is_raw_union) str = gb_string_appendc(str, " #raw_union");
if (type->Struct.is_no_copy) str = gb_string_appendc(str, " #no_copy");
if (type->Struct.custom_align != 0) str = gb_string_append_fmt(str, " #align %d", cast(int)type->Struct.custom_align);
str = gb_string_appendc(str, " {");

View File

@@ -269,6 +269,12 @@ TestECDH :: struct {
test_x25519 :: proc(t: ^testing.T) {
log(t, "Testing X25519")
// Local copy of this so that the base point doesn't need to be exported.
_BASE_POINT: [32]byte = {
9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}
test_vectors := [?]TestECDH {
// Test vectors from RFC 7748
TestECDH{
@@ -295,7 +301,7 @@ test_x25519 :: proc(t: ^testing.T) {
// Abuse the test vectors to sanity-check the scalar-basepoint multiply.
p1, p2: [x25519.POINT_SIZE]byte
x25519.scalarmult_basepoint(p1[:], scalar[:])
x25519.scalarmult(p2[:], scalar[:], x25519._BASE_POINT[:])
x25519.scalarmult(p2[:], scalar[:], _BASE_POINT[:])
p1_str, p2_str := hex_string(p1[:]), hex_string(p2[:])
expect(t, p1_str == p2_str, fmt.tprintf("Expected %s for %s * basepoint, but got %s instead", p2_str, v.scalar, p1_str))
}

View File

@@ -5,6 +5,7 @@ import "core:testing"
import "core:fmt"
import "core:os"
import "core:runtime"
import "core:mem"
TEST_count := 0
TEST_fail := 0
@@ -105,33 +106,46 @@ Case_Kind :: enum {
Ada_Case,
}
test_cases := [Case_Kind]struct{s: string, p: proc(r: string, allocator: runtime.Allocator) -> string}{
Case_Proc :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error)
test_cases := [Case_Kind]struct{s: string, p: Case_Proc}{
.Lower_Space_Case = {"hellope world", to_lower_space_case},
.Upper_Space_Case = {"HELLOPE WORLD", to_upper_space_case},
.Lower_Snake_Case = {"hellope_world", strings.to_snake_case},
.Upper_Snake_Case = {"HELLOPE_WORLD", strings.to_upper_snake_case},
.Lower_Kebab_Case = {"hellope-world", strings.to_kebab_case},
.Upper_Kebab_Case = {"HELLOPE-WORLD", strings.to_upper_kebab_case},
.Camel_Case = {"hellopeWorld", strings.to_camel_case},
.Pascal_Case = {"HellopeWorld", strings.to_pascal_case},
.Ada_Case = {"Hellope_World", strings.to_ada_case},
.Lower_Snake_Case = {"hellope_world", to_snake_case},
.Upper_Snake_Case = {"HELLOPE_WORLD", to_upper_snake_case},
.Lower_Kebab_Case = {"hellope-world", to_kebab_case},
.Upper_Kebab_Case = {"HELLOPE-WORLD", to_upper_kebab_case},
.Camel_Case = {"hellopeWorld", to_camel_case},
.Pascal_Case = {"HellopeWorld", to_pascal_case},
.Ada_Case = {"Hellope_World", to_ada_case},
}
to_lower_space_case :: proc(r: string, allocator: runtime.Allocator) -> string {
to_lower_space_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) {
return strings.to_delimiter_case(r, ' ', false, allocator)
}
to_upper_space_case :: proc(r: string, allocator: runtime.Allocator) -> string {
to_upper_space_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) {
return strings.to_delimiter_case(r, ' ', true, allocator)
}
// NOTE: we have these wrappers as having #optional_allocator_error changes the type to not be equivalent
to_snake_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_snake_case(r, allocator) }
to_upper_snake_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_upper_snake_case(r, allocator) }
to_kebab_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_kebab_case(r, allocator) }
to_upper_kebab_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_upper_kebab_case(r, allocator) }
to_camel_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_camel_case(r, allocator) }
to_pascal_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_pascal_case(r, allocator) }
to_ada_case :: proc(r: string, allocator: runtime.Allocator) -> (string, mem.Allocator_Error) { return strings.to_ada_case(r, allocator) }
@test
test_case_conversion :: proc(t: ^testing.T) {
for entry in test_cases {
for test_case, case_kind in test_cases {
result := entry.p(test_case.s, context.allocator)
result, err := entry.p(test_case.s, context.allocator)
msg := fmt.tprintf("ERROR: We got the allocation error '{}'\n", err)
expect(t, err == nil, msg)
defer delete(result)
msg := fmt.tprintf("ERROR: Input `{}` to converter {} does not match `{}`, got `{}`.\n", test_case.s, case_kind, entry.s, result)
msg = fmt.tprintf("ERROR: Input `{}` to converter {} does not match `{}`, got `{}`.\n", test_case.s, case_kind, entry.s, result)
expect(t, result == entry.s, msg)
}
}

View File

@@ -327,7 +327,16 @@ main :: proc() {
os.stdout = _write_pipe
_spawn_pipe_reader()
`)
Found_Proc :: struct {
name: string,
type: string,
}
found_procedures_for_error_msg: [dynamic]Found_Proc
for test in example_tests {
fmt.printf("--- Generating documentation test for \"%v.%v\"\n", test.package_name, test.entity_name)
clear(&found_procedures_for_error_msg)
strings.builder_reset(&example_build)
strings.write_string(&example_build, "package documentation_verification\n\n")
for line in test.example_code {
@@ -364,6 +373,10 @@ main :: proc() {
proc_lit, is_proc_lit := value_decl.values[0].derived_expr.(^ast.Proc_Lit); if ! is_proc_lit {
continue
}
append(&found_procedures_for_error_msg, Found_Proc {
name = code_string[value_decl.names[0].pos.offset:value_decl.names[0].end.offset],
type = code_string[proc_lit.type.pos.offset:proc_lit.type.end.offset],
})
if len(proc_lit.type.params.list) > 0 {
continue
}
@@ -377,17 +390,38 @@ main :: proc() {
}
if code_test_name == "" {
fmt.eprintf("We could not any find procedure literals with no arguments with the identifier %q for the example for %q\n", enforced_name, test.entity_name)
g_bad_doc = true
fmt.eprintf("We could not find the procedure \"%s :: proc()\" needed to test the example created for \"%s.%s\"\n", enforced_name, test.package_name, test.entity_name)
if len(found_procedures_for_error_msg) > 0{
fmt.eprint("The following procedures were found:\n")
for procedure in found_procedures_for_error_msg {
fmt.eprintf("\t%s :: %s\n", procedure.name, procedure.type)
}
} else {
fmt.eprint("No procedures were found?\n")
}
// NOTE: we don't want to fail the CI in this case, just put the error in the log and test everything else
// g_bad_doc = true
continue
}
fmt.sbprintf(&test_runner, "\t%v_%v()\n", test.package_name, code_test_name)
fmt.sbprintf(&test_runner, "\t_check(%q, `", code_test_name)
had_line_error: bool
for line in test.expected_output {
// NOTE: this will escape the multiline string. Even with a backslash it still escapes due to the semantics of `
// I don't think any examples would really need this specific character so let's just make it forbidden and change
// in the future if we really need to
if strings.contains_rune(line, '`') {
fmt.eprintf("The line %q in the output for \"%s.%s\" contains a ` which is not allowed\n", line, test.package_name, test.entity_name)
g_bad_doc = true
had_line_error = true
}
strings.write_string(&test_runner, line)
strings.write_string(&test_runner, "\n")
}
if had_line_error {
continue
}
strings.write_string(&test_runner, "`)\n")
save_path := fmt.tprintf("verify/test_%v_%v.odin", test.package_name, code_test_name)
@@ -404,6 +438,7 @@ main :: proc() {
continue
}
fmt.wprintf(writer, "%v%v_%v", code_string[:index_of_proc_name], test.package_name, code_string[index_of_proc_name:])
fmt.println("Done")
}
strings.write_string(&test_runner,

174
vendor/lua/5.1/include/lauxlib.h vendored Normal file
View File

@@ -0,0 +1,174 @@
/*
** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
#ifndef lauxlib_h
#define lauxlib_h
#include <stddef.h>
#include <stdio.h>
#include "lua.h"
#if defined(LUA_COMPAT_GETN)
LUALIB_API int (luaL_getn) (lua_State *L, int t);
LUALIB_API void (luaL_setn) (lua_State *L, int t, int n);
#else
#define luaL_getn(L,i) ((int)lua_objlen(L, i))
#define luaL_setn(L,i,j) ((void)0) /* no op! */
#endif
#if defined(LUA_COMPAT_OPENLIB)
#define luaI_openlib luaL_openlib
#endif
/* extra error code for `luaL_load' */
#define LUA_ERRFILE (LUA_ERRERR+1)
typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;
LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname,
const luaL_Reg *l, int nup);
LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
const luaL_Reg *l);
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname);
LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
size_t *l);
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
const char *def, size_t *l);
LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
lua_Integer def);
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_where) (lua_State *L, int lvl);
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
const char *const lst[]);
LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
const char *name);
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
const char *r);
LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
const char *fname, int szhint);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define luaL_argcheck(L, cond,numarg,extramsg) \
((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_dostring(L, s) \
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
typedef struct luaL_Buffer {
char *p; /* current position in buffer */
int lvl; /* number of strings in the stack (level) */
lua_State *L;
char buffer[LUAL_BUFFERSIZE];
} luaL_Buffer;
#define luaL_addchar(B,c) \
((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
(*(B)->p++ = (char)(c)))
/* compatibility only */
#define luaL_putchar(B,c) luaL_addchar(B,c)
#define luaL_addsize(B,n) ((B)->p += (n))
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B);
LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
/* }====================================================== */
/* compatibility with ref system */
/* pre-defined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
(lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))
#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref))
#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref))
#define luaL_reg luaL_Reg
#endif

388
vendor/lua/5.1/include/lua.h vendored Normal file
View File

@@ -0,0 +1,388 @@
/*
** $Id: lua.h,v 1.218.1.7 2012/01/13 20:36:20 roberto Exp $
** Lua - An Extensible Extension Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
*/
#ifndef lua_h
#define lua_h
#include <stdarg.h>
#include <stddef.h>
#include "luaconf.h"
#define LUA_VERSION "Lua 5.1"
#define LUA_RELEASE "Lua 5.1.5"
#define LUA_VERSION_NUM 501
#define LUA_COPYRIGHT "Copyright (C) 1994-2012 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
/* mark for precompiled code (`<esc>Lua') */
#define LUA_SIGNATURE "\033Lua"
/* option for multiple returns in `lua_pcall' and `lua_call' */
#define LUA_MULTRET (-1)
/*
** pseudo-indices
*/
#define LUA_REGISTRYINDEX (-10000)
#define LUA_ENVIRONINDEX (-10001)
#define LUA_GLOBALSINDEX (-10002)
#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i))
/* thread status; 0 is OK */
#define LUA_YIELD 1
#define LUA_ERRRUN 2
#define LUA_ERRSYNTAX 3
#define LUA_ERRMEM 4
#define LUA_ERRERR 5
typedef struct lua_State lua_State;
typedef int (*lua_CFunction) (lua_State *L);
/*
** functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
/*
** prototype for memory-allocation functions
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
** basic types
*/
#define LUA_TNONE (-1)
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TLIGHTUSERDATA 2
#define LUA_TNUMBER 3
#define LUA_TSTRING 4
#define LUA_TTABLE 5
#define LUA_TFUNCTION 6
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8
/* minimum Lua stack available to a C function */
#define LUA_MINSTACK 20
/*
** generic extra include file
*/
#if defined(LUA_USER_H)
#include LUA_USER_H
#endif
/* type of numbers in Lua */
typedef LUA_NUMBER lua_Number;
/* type for integer functions */
typedef LUA_INTEGER lua_Integer;
/*
** state manipulation
*/
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L);
LUA_API lua_State *(lua_newthread) (lua_State *L);
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
/*
** basic stack manipulation
*/
LUA_API int (lua_gettop) (lua_State *L);
LUA_API void (lua_settop) (lua_State *L, int idx);
LUA_API void (lua_pushvalue) (lua_State *L, int idx);
LUA_API void (lua_remove) (lua_State *L, int idx);
LUA_API void (lua_insert) (lua_State *L, int idx);
LUA_API void (lua_replace) (lua_State *L, int idx);
LUA_API int (lua_checkstack) (lua_State *L, int sz);
LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
/*
** access functions (stack -> C)
*/
LUA_API int (lua_isnumber) (lua_State *L, int idx);
LUA_API int (lua_isstring) (lua_State *L, int idx);
LUA_API int (lua_iscfunction) (lua_State *L, int idx);
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
LUA_API int (lua_type) (lua_State *L, int idx);
LUA_API const char *(lua_typename) (lua_State *L, int tp);
LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2);
LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx);
LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx);
LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API size_t (lua_objlen) (lua_State *L, int idx);
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
/*
** push functions (C -> stack)
*/
LUA_API void (lua_pushnil) (lua_State *L);
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l);
LUA_API void (lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);
/*
** get functions (Lua -> stack)
*/
LUA_API void (lua_gettable) (lua_State *L, int idx);
LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_rawget) (lua_State *L, int idx);
LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
LUA_API void (lua_getfenv) (lua_State *L, int idx);
/*
** set functions (stack -> Lua)
*/
LUA_API void (lua_settable) (lua_State *L, int idx);
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_rawset) (lua_State *L, int idx);
LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
LUA_API int (lua_setfenv) (lua_State *L, int idx);
/*
** `load' and `call' functions (load and run Lua code)
*/
LUA_API void (lua_call) (lua_State *L, int nargs, int nresults);
LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc);
LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud);
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname);
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
/*
** coroutine functions
*/
LUA_API int (lua_yield) (lua_State *L, int nresults);
LUA_API int (lua_resume) (lua_State *L, int narg);
LUA_API int (lua_status) (lua_State *L);
/*
** garbage-collection function and options
*/
#define LUA_GCSTOP 0
#define LUA_GCRESTART 1
#define LUA_GCCOLLECT 2
#define LUA_GCCOUNT 3
#define LUA_GCCOUNTB 4
#define LUA_GCSTEP 5
#define LUA_GCSETPAUSE 6
#define LUA_GCSETSTEPMUL 7
LUA_API int (lua_gc) (lua_State *L, int what, int data);
/*
** miscellaneous functions
*/
LUA_API int (lua_error) (lua_State *L);
LUA_API int (lua_next) (lua_State *L, int idx);
LUA_API void (lua_concat) (lua_State *L, int n);
LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
#define lua_strlen(L,i) lua_objlen(L, (i))
#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
#define lua_pushliteral(L, s) \
lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s))
#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s))
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
/*
** compatibility macros and functions
*/
#define lua_open() luaL_newstate()
#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX)
#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0)
#define lua_Chunkreader lua_Reader
#define lua_Chunkwriter lua_Writer
/* hack */
LUA_API void lua_setlevel (lua_State *from, lua_State *to);
/*
** {======================================================================
** Debug API
** =======================================================================
*/
/*
** Event codes
*/
#define LUA_HOOKCALL 0
#define LUA_HOOKRET 1
#define LUA_HOOKLINE 2
#define LUA_HOOKCOUNT 3
#define LUA_HOOKTAILRET 4
/*
** Event masks
*/
#define LUA_MASKCALL (1 << LUA_HOOKCALL)
#define LUA_MASKRET (1 << LUA_HOOKRET)
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
typedef struct lua_Debug lua_Debug; /* activation record */
/* Functions to be called by the debuger in specific events */
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook lua_gethook (lua_State *L);
LUA_API int lua_gethookmask (lua_State *L);
LUA_API int lua_gethookcount (lua_State *L);
struct lua_Debug {
int event;
const char *name; /* (n) */
const char *namewhat; /* (n) `global', `local', `field', `method' */
const char *what; /* (S) `Lua', `C', `main', `tail' */
const char *source; /* (S) */
int currentline; /* (l) */
int nups; /* (u) number of upvalues */
int linedefined; /* (S) */
int lastlinedefined; /* (S) */
char short_src[LUA_IDSIZE]; /* (S) */
/* private part */
int i_ci; /* active function */
};
/* }====================================================================== */
/******************************************************************************
* Copyright (C) 1994-2012 Lua.org, PUC-Rio. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#endif

9
vendor/lua/5.1/include/lua.hpp vendored Normal file
View File

@@ -0,0 +1,9 @@
// lua.hpp
// Lua header files for C++
// <<extern "C">> not supplied automatically because Lua also compiles as C++
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

766
vendor/lua/5.1/include/luaconf.h vendored Normal file
View File

@@ -0,0 +1,766 @@
/*
** $Id: luaconf.h,v 1.82.1.7 2008/02/11 16:25:08 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
#ifndef lconfig_h
#define lconfig_h
#include <limits.h>
#include <stddef.h>
/*
** ==================================================================
** Search for "@@" to find all configurable definitions.
** ===================================================================
*/
/*
@@ LUA_ANSI controls the use of non-ansi features.
** CHANGE it (define it) if you want Lua to avoid the use of any
** non-ansi feature or library.
*/
#if defined(__STRICT_ANSI__)
#define LUA_ANSI
#endif
#if !defined(LUA_ANSI) && defined(_WIN32)
#define LUA_WIN
#endif
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
#define LUA_USE_READLINE /* needs some extra libraries */
#endif
#if defined(LUA_USE_MACOSX)
#define LUA_USE_POSIX
#define LUA_DL_DYLD /* does not need extra library */
#endif
/*
@@ LUA_USE_POSIX includes all functionallity listed as X/Open System
@* Interfaces Extension (XSI).
** CHANGE it (define it) if your system is XSI compatible.
*/
#if defined(LUA_USE_POSIX)
#define LUA_USE_MKSTEMP
#define LUA_USE_ISATTY
#define LUA_USE_POPEN
#define LUA_USE_ULONGJMP
#endif
/*
@@ LUA_PATH and LUA_CPATH are the names of the environment variables that
@* Lua check to set its paths.
@@ LUA_INIT is the name of the environment variable that Lua
@* checks for initialization code.
** CHANGE them if you want different names.
*/
#define LUA_PATH "LUA_PATH"
#define LUA_CPATH "LUA_CPATH"
#define LUA_INIT "LUA_INIT"
/*
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
@* Lua libraries.
@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
@* C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
** non-conventional directories.
*/
#if defined(_WIN32)
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
*/
#define LUA_LDIR "!\\lua\\"
#define LUA_CDIR "!\\"
#define LUA_PATH_DEFAULT \
".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua"
#define LUA_CPATH_DEFAULT \
".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll;" \
LUA_CDIR"clibs\\?.dll;" LUA_CDIR"clibs\\loadall.dll;" \
".\\?51.dll;" LUA_CDIR"?51.dll;" LUA_CDIR"clibs\\?51.dll"
#else
#define LUA_ROOT "/usr/local/"
#define LUA_LDIR LUA_ROOT "share/lua/5.1/"
#define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
#define LUA_PATH_DEFAULT \
"./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"
#define LUA_CPATH_DEFAULT \
"./?.so;" LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" \
"./lib?51.so;" LUA_CDIR"lib?51.so"
#endif
/*
@@ LUA_DIRSEP is the directory separator (for submodules).
** CHANGE it if your machine does not use "/" as the directory separator
** and is not Windows. (On Windows Lua automatically uses "\".)
*/
#if defined(_WIN32)
#define LUA_DIRSEP "\\"
#else
#define LUA_DIRSEP "/"
#endif
/*
@@ LUA_PATHSEP is the character that separates templates in a path.
@@ LUA_PATH_MARK is the string that marks the substitution points in a
@* template.
@@ LUA_EXECDIR in a Windows path is replaced by the executable's
@* directory.
@@ LUA_IGMARK is a mark to ignore all before it when bulding the
@* luaopen_ function name.
** CHANGE them if for some reason your system cannot use those
** characters. (E.g., if one of those characters is a common character
** in file/directory names.) Probably you do not need to change them.
*/
#define LUA_PATHSEP ";"
#define LUA_PATH_MARK "?"
#define LUA_EXECDIR "!"
#define LUA_IGMARK "-"
/*
@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
** machines, ptrdiff_t gives a good choice between int or long.)
*/
#define LUA_INTEGER ptrdiff_t
/*
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all standard library functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
*/
#if defined(LUA_BUILD_AS_DLL)
#if defined(LUA_CORE) || defined(LUA_LIB)
#define LUA_API __declspec(dllexport)
#else
#define LUA_API __declspec(dllimport)
#endif
#else
#define LUA_API extern
#endif
/* more often than not the libs go together with the core */
#define LUALIB_API LUA_API
/*
@@ LUAI_FUNC is a mark for all extern functions that are not to be
@* exported to outside modules.
@@ LUAI_DATA is a mark for all extern (const) variables that are not to
@* be exported to outside modules.
** CHANGE them if you need to mark them in some special way. Elf/gcc
** (versions 3.2 and later) mark them as "hidden" to optimize access
** when Lua is compiled as a shared library.
*/
#if defined(luaall_c)
#define LUAI_FUNC static
#define LUAI_DATA /* empty */
#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
defined(__ELF__)
#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
#define LUAI_DATA LUAI_FUNC
#else
#define LUAI_FUNC extern
#define LUAI_DATA extern
#endif
/*
@@ LUA_QL describes how error messages quote program elements.
** CHANGE it if you want a different appearance.
*/
#define LUA_QL(x) "'" x "'"
#define LUA_QS LUA_QL("%s")
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@* of a function in debug information.
** CHANGE it if you want a different size.
*/
#define LUA_IDSIZE 60
/*
** {==================================================================
** Stand-alone configuration
** ===================================================================
*/
#if defined(lua_c) || defined(luaall_c)
/*
@@ lua_stdin_is_tty detects whether the standard input is a 'tty' (that
@* is, whether we're running lua interactively).
** CHANGE it if you have a better definition for non-POSIX/non-Windows
** systems.
*/
#if defined(LUA_USE_ISATTY)
#include <unistd.h>
#define lua_stdin_is_tty() isatty(0)
#elif defined(LUA_WIN)
#include <io.h>
#include <stdio.h>
#define lua_stdin_is_tty() _isatty(_fileno(stdin))
#else
#define lua_stdin_is_tty() 1 /* assume stdin is a tty */
#endif
/*
@@ LUA_PROMPT is the default prompt used by stand-alone Lua.
@@ LUA_PROMPT2 is the default continuation prompt used by stand-alone Lua.
** CHANGE them if you want different prompts. (You can also change the
** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
*/
#define LUA_PROMPT "> "
#define LUA_PROMPT2 ">> "
/*
@@ LUA_PROGNAME is the default name for the stand-alone Lua program.
** CHANGE it if your stand-alone interpreter has a different name and
** your system is not able to detect that name automatically.
*/
#define LUA_PROGNAME "lua"
/*
@@ LUA_MAXINPUT is the maximum length for an input line in the
@* stand-alone interpreter.
** CHANGE it if you need longer lines.
*/
#define LUA_MAXINPUT 512
/*
@@ lua_readline defines how to show a prompt and then read a line from
@* the standard input.
@@ lua_saveline defines how to "save" a read line in a "history".
@@ lua_freeline defines how to free a line read by lua_readline.
** CHANGE them if you want to improve this functionality (e.g., by using
** GNU readline and history facilities).
*/
#if defined(LUA_USE_READLINE)
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
#define lua_readline(L,b,p) ((void)L, ((b)=readline(p)) != NULL)
#define lua_saveline(L,idx) \
if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
add_history(lua_tostring(L, idx)); /* add it to history */
#define lua_freeline(L,b) ((void)L, free(b))
#else
#define lua_readline(L,b,p) \
((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
#define lua_saveline(L,idx) { (void)L; (void)idx; }
#define lua_freeline(L,b) { (void)L; (void)b; }
#endif
#endif
/* }================================================================== */
/*
@@ LUAI_GCPAUSE defines the default pause between garbage-collector cycles
@* as a percentage.
** CHANGE it if you want the GC to run faster or slower (higher values
** mean larger pauses which mean slower collection.) You can also change
** this value dynamically.
*/
#define LUAI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */
/*
@@ LUAI_GCMUL defines the default speed of garbage collection relative to
@* memory allocation as a percentage.
** CHANGE it if you want to change the granularity of the garbage
** collection. (Higher values mean coarser collections. 0 represents
** infinity, where each step performs a full collection.) You can also
** change this value dynamically.
*/
#define LUAI_GCMUL 200 /* GC runs 'twice the speed' of memory allocation */
/*
@@ LUA_COMPAT_GETN controls compatibility with old getn behavior.
** CHANGE it (define it) if you want exact compatibility with the
** behavior of setn/getn in Lua 5.0.
*/
#undef LUA_COMPAT_GETN
/*
@@ LUA_COMPAT_LOADLIB controls compatibility about global loadlib.
** CHANGE it to undefined as soon as you do not need a global 'loadlib'
** function (the function is still available as 'package.loadlib').
*/
#undef LUA_COMPAT_LOADLIB
/*
@@ LUA_COMPAT_VARARG controls compatibility with old vararg feature.
** CHANGE it to undefined as soon as your programs use only '...' to
** access vararg parameters (instead of the old 'arg' table).
*/
#define LUA_COMPAT_VARARG
/*
@@ LUA_COMPAT_MOD controls compatibility with old math.mod function.
** CHANGE it to undefined as soon as your programs use 'math.fmod' or
** the new '%' operator instead of 'math.mod'.
*/
#define LUA_COMPAT_MOD
/*
@@ LUA_COMPAT_LSTR controls compatibility with old long string nesting
@* facility.
** CHANGE it to 2 if you want the old behaviour, or undefine it to turn
** off the advisory error when nesting [[...]].
*/
#define LUA_COMPAT_LSTR 1
/*
@@ LUA_COMPAT_GFIND controls compatibility with old 'string.gfind' name.
** CHANGE it to undefined as soon as you rename 'string.gfind' to
** 'string.gmatch'.
*/
#define LUA_COMPAT_GFIND
/*
@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
@* behavior.
** CHANGE it to undefined as soon as you replace to 'luaL_register'
** your uses of 'luaL_openlib'
*/
#define LUA_COMPAT_OPENLIB
/*
@@ luai_apicheck is the assert macro used by the Lua-C API.
** CHANGE luai_apicheck if you want Lua to perform some checks in the
** parameters it gets from API calls. This may slow down the interpreter
** a bit, but may be quite useful when debugging C code that interfaces
** with Lua. A useful redefinition is to use assert.h.
*/
#if defined(LUA_USE_APICHECK)
#include <assert.h>
#define luai_apicheck(L,o) { (void)L; assert(o); }
#else
#define luai_apicheck(L,o) { (void)L; }
#endif
/*
@@ LUAI_BITSINT defines the number of bits in an int.
** CHANGE here if Lua cannot automatically detect the number of bits of
** your machine. Probably you do not need to change this.
*/
/* avoid overflows in comparison */
#if INT_MAX-20 < 32760
#define LUAI_BITSINT 16
#elif INT_MAX > 2147483640L
/* int has at least 32 bits */
#define LUAI_BITSINT 32
#else
#error "you must define LUA_BITSINT with number of bits in an integer"
#endif
/*
@@ LUAI_UINT32 is an unsigned integer with at least 32 bits.
@@ LUAI_INT32 is an signed integer with at least 32 bits.
@@ LUAI_UMEM is an unsigned integer big enough to count the total
@* memory used by Lua.
@@ LUAI_MEM is a signed integer big enough to count the total memory
@* used by Lua.
** CHANGE here if for some weird reason the default definitions are not
** good enough for your machine. (The definitions in the 'else'
** part always works, but may waste space on machines with 64-bit
** longs.) Probably you do not need to change this.
*/
#if LUAI_BITSINT >= 32
#define LUAI_UINT32 unsigned int
#define LUAI_INT32 int
#define LUAI_MAXINT32 INT_MAX
#define LUAI_UMEM size_t
#define LUAI_MEM ptrdiff_t
#else
/* 16-bit ints */
#define LUAI_UINT32 unsigned long
#define LUAI_INT32 long
#define LUAI_MAXINT32 LONG_MAX
#define LUAI_UMEM unsigned long
#define LUAI_MEM long
#endif
/*
@@ LUAI_MAXCALLS limits the number of nested calls.
** CHANGE it if you need really deep recursive calls. This limit is
** arbitrary; its only purpose is to stop infinite recursion before
** exhausting memory.
*/
#define LUAI_MAXCALLS 20000
/*
@@ LUAI_MAXCSTACK limits the number of Lua stack slots that a C function
@* can use.
** CHANGE it if you need lots of (Lua) stack space for your C
** functions. This limit is arbitrary; its only purpose is to stop C
** functions to consume unlimited stack space. (must be smaller than
** -LUA_REGISTRYINDEX)
*/
#define LUAI_MAXCSTACK 8000
/*
** {==================================================================
** CHANGE (to smaller values) the following definitions if your system
** has a small C stack. (Or you may want to change them to larger
** values if your system has a large C stack and these limits are
** too rigid for you.) Some of these constants control the size of
** stack-allocated arrays used by the compiler or the interpreter, while
** others limit the maximum number of recursive calls that the compiler
** or the interpreter can perform. Values too large may cause a C stack
** overflow for some forms of deep constructs.
** ===================================================================
*/
/*
@@ LUAI_MAXCCALLS is the maximum depth for nested C calls (short) and
@* syntactical nested non-terminals in a program.
*/
#define LUAI_MAXCCALLS 200
/*
@@ LUAI_MAXVARS is the maximum number of local variables per function
@* (must be smaller than 250).
*/
#define LUAI_MAXVARS 200
/*
@@ LUAI_MAXUPVALUES is the maximum number of upvalues per function
@* (must be smaller than 250).
*/
#define LUAI_MAXUPVALUES 60
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
*/
#define LUAL_BUFFERSIZE BUFSIZ
/* }================================================================== */
/*
** {==================================================================
@@ LUA_NUMBER is the type of numbers in Lua.
** CHANGE the following definitions only if you want to build Lua
** with a number type different from double. You may also need to
** change lua_number2int & lua_number2integer.
** ===================================================================
*/
#define LUA_NUMBER_DOUBLE
#define LUA_NUMBER double
/*
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@* over a number.
*/
#define LUAI_UACNUMBER double
/*
@@ LUA_NUMBER_SCAN is the format for reading numbers.
@@ LUA_NUMBER_FMT is the format for writing numbers.
@@ lua_number2str converts a number to a string.
@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
@@ lua_str2number converts a string to a number.
*/
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g"
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
#define lua_str2number(s,p) strtod((s), (p))
/*
@@ The luai_num* macros define the primitive operations over numbers.
*/
#if defined(LUA_CORE)
#include <math.h>
#define luai_numadd(a,b) ((a)+(b))
#define luai_numsub(a,b) ((a)-(b))
#define luai_nummul(a,b) ((a)*(b))
#define luai_numdiv(a,b) ((a)/(b))
#define luai_nummod(a,b) ((a) - floor((a)/(b))*(b))
#define luai_numpow(a,b) (pow(a,b))
#define luai_numunm(a) (-(a))
#define luai_numeq(a,b) ((a)==(b))
#define luai_numlt(a,b) ((a)<(b))
#define luai_numle(a,b) ((a)<=(b))
#define luai_numisnan(a) (!luai_numeq((a), (a)))
#endif
/*
@@ lua_number2int is a macro to convert lua_Number to int.
@@ lua_number2integer is a macro to convert lua_Number to lua_Integer.
** CHANGE them if you know a faster way to convert a lua_Number to
** int (with any rounding method and without throwing errors) in your
** system. In Pentium machines, a naive typecast from double to int
** in C is extremely slow, so any alternative is worth trying.
*/
/* On a Pentium, resort to a trick */
#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \
(defined(__i386) || defined (_M_IX86) || defined(__i386__))
/* On a Microsoft compiler, use assembler */
#if defined(_MSC_VER)
#define lua_number2int(i,d) __asm fld d __asm fistp i
#define lua_number2integer(i,n) lua_number2int(i, n)
/* the next trick should work on any Pentium, but sometimes clashes
with a DirectX idiosyncrasy */
#else
union luai_Cast { double l_d; long l_l; };
#define lua_number2int(i,d) \
{ volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; }
#define lua_number2integer(i,n) lua_number2int(i, n)
#endif
/* this option always works, but may be slow */
#else
#define lua_number2int(i,d) ((i)=(int)(d))
#define lua_number2integer(i,d) ((i)=(lua_Integer)(d))
#endif
/* }================================================================== */
/*
@@ LUAI_USER_ALIGNMENT_T is a type that requires maximum alignment.
** CHANGE it if your system requires alignments larger than double. (For
** instance, if your system supports long doubles and they must be
** aligned in 16-byte boundaries, then you should add long double in the
** union.) Probably you do not need to change this.
*/
#define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
/*
@@ LUAI_THROW/LUAI_TRY define how Lua does exception handling.
** CHANGE them if you prefer to use longjmp/setjmp even with C++
** or if want/don't to use _longjmp/_setjmp instead of regular
** longjmp/setjmp. By default, Lua handles errors with exceptions when
** compiling as C++ code, with _longjmp/_setjmp when asked to use them,
** and with longjmp/setjmp otherwise.
*/
#if defined(__cplusplus)
/* C++ exceptions */
#define LUAI_THROW(L,c) throw(c)
#define LUAI_TRY(L,c,a) try { a } catch(...) \
{ if ((c)->status == 0) (c)->status = -1; }
#define luai_jmpbuf int /* dummy variable */
#elif defined(LUA_USE_ULONGJMP)
/* in Unix, try _longjmp/_setjmp (more efficient) */
#define LUAI_THROW(L,c) _longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a) if (_setjmp((c)->b) == 0) { a }
#define luai_jmpbuf jmp_buf
#else
/* default handling with long jumps */
#define LUAI_THROW(L,c) longjmp((c)->b, 1)
#define LUAI_TRY(L,c,a) if (setjmp((c)->b) == 0) { a }
#define luai_jmpbuf jmp_buf
#endif
/*
@@ LUA_MAXCAPTURES is the maximum number of captures that a pattern
@* can do during pattern-matching.
** CHANGE it if you need more captures. This limit is arbitrary.
*/
#define LUA_MAXCAPTURES 32
/*
@@ lua_tmpnam is the function that the OS library uses to create a
@* temporary name.
@@ LUA_TMPNAMBUFSIZE is the maximum size of a name created by lua_tmpnam.
** CHANGE them if you have an alternative to tmpnam (which is considered
** insecure) or if you want the original tmpnam anyway. By default, Lua
** uses tmpnam except when POSIX is available, where it uses mkstemp.
*/
#if defined(loslib_c) || defined(luaall_c)
#if defined(LUA_USE_MKSTEMP)
#include <unistd.h>
#define LUA_TMPNAMBUFSIZE 32
#define lua_tmpnam(b,e) { \
strcpy(b, "/tmp/lua_XXXXXX"); \
e = mkstemp(b); \
if (e != -1) close(e); \
e = (e == -1); }
#else
#define LUA_TMPNAMBUFSIZE L_tmpnam
#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
#endif
#endif
/*
@@ lua_popen spawns a new process connected to the current one through
@* the file streams.
** CHANGE it if you have a way to implement it in your system.
*/
#if defined(LUA_USE_POPEN)
#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
#elif defined(LUA_WIN)
#define lua_popen(L,c,m) ((void)L, _popen(c,m))
#define lua_pclose(L,file) ((void)L, (_pclose(file) != -1))
#else
#define lua_popen(L,c,m) ((void)((void)c, m), \
luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
#define lua_pclose(L,file) ((void)((void)L, file), 0)
#endif
/*
@@ LUA_DL_* define which dynamic-library system Lua should use.
** CHANGE here if Lua has problems choosing the appropriate
** dynamic-library system for your platform (either Windows' DLL, Mac's
** dyld, or Unix's dlopen). If your system is some kind of Unix, there
** is a good chance that it has dlopen, so LUA_DL_DLOPEN will work for
** it. To use dlopen you also need to adapt the src/Makefile (probably
** adding -ldl to the linker options), so Lua does not select it
** automatically. (When you change the makefile to add -ldl, you must
** also add -DLUA_USE_DLOPEN.)
** If you do not want any kind of dynamic library, undefine all these
** options.
** By default, _WIN32 gets LUA_DL_DLL and MAC OS X gets LUA_DL_DYLD.
*/
#if defined(LUA_USE_DLOPEN)
#define LUA_DL_DLOPEN
#endif
#if defined(LUA_WIN)
#define LUA_DL_DLL
#endif
/*
@@ LUAI_EXTRASPACE allows you to add user-specific data in a lua_State
@* (the data goes just *before* the lua_State pointer).
** CHANGE (define) this if you really need that. This value must be
** a multiple of the maximum alignment required for your machine.
*/
#define LUAI_EXTRASPACE 0
/*
@@ luai_userstate* allow user-specific actions on threads.
** CHANGE them if you defined LUAI_EXTRASPACE and need to do something
** extra when a thread is created/deleted/resumed/yielded.
*/
#define luai_userstateopen(L) ((void)L)
#define luai_userstateclose(L) ((void)L)
#define luai_userstatethread(L,L1) ((void)L)
#define luai_userstatefree(L) ((void)L)
#define luai_userstateresume(L,n) ((void)L)
#define luai_userstateyield(L,n) ((void)L)
/*
@@ LUA_INTFRMLEN is the length modifier for integer conversions
@* in 'string.format'.
@@ LUA_INTFRM_T is the integer type correspoding to the previous length
@* modifier.
** CHANGE them if your system supports long long or does not support long.
*/
#if defined(LUA_USELONGLONG)
#define LUA_INTFRMLEN "ll"
#define LUA_INTFRM_T long long
#else
#define LUA_INTFRMLEN "l"
#define LUA_INTFRM_T long
#endif
/* =================================================================== */
/*
** Local configuration. You can use this space to add your redefinitions
** without modifying the main part of the file.
*/
#endif

53
vendor/lua/5.1/include/lualib.h vendored Normal file
View File

@@ -0,0 +1,53 @@
/*
** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
#ifndef lualib_h
#define lualib_h
#include "lua.h"
/* Key to file-handle type */
#define LUA_FILEHANDLE "FILE*"
#define LUA_COLIBNAME "coroutine"
LUALIB_API int (luaopen_base) (lua_State *L);
#define LUA_TABLIBNAME "table"
LUALIB_API int (luaopen_table) (lua_State *L);
#define LUA_IOLIBNAME "io"
LUALIB_API int (luaopen_io) (lua_State *L);
#define LUA_OSLIBNAME "os"
LUALIB_API int (luaopen_os) (lua_State *L);
#define LUA_STRLIBNAME "string"
LUALIB_API int (luaopen_string) (lua_State *L);
#define LUA_MATHLIBNAME "math"
LUALIB_API int (luaopen_math) (lua_State *L);
#define LUA_DBLIBNAME "debug"
LUALIB_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUALIB_API int (luaopen_package) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);
#ifndef lua_assert
#define lua_assert(x) ((void)0)
#endif
#endif

BIN
vendor/lua/5.1/linux/liblua5.1.a vendored Normal file

Binary file not shown.

BIN
vendor/lua/5.1/linux/liblua5.1.so vendored Normal file

Binary file not shown.

659
vendor/lua/5.1/lua.odin vendored Normal file
View File

@@ -0,0 +1,659 @@
package lua_5_1
import "core:intrinsics"
import "core:builtin"
import c "core:c/libc"
#assert(size_of(c.int) == size_of(b32))
when ODIN_OS == .Windows {
foreign import lib "windows/lua5.1.dll.lib"
} else when ODIN_OS == .Linux {
foreign import lib "linux/liblua5.1.a"
} else {
foreign import lib "system:liblua5.1.a"
}
VERSION :: "Lua 5.1"
RELEASE :: "Lua 5.1.5"
VERSION_NUM :: 501
COPYRIGHT :: "Copyright (C) 1994-2012 Lua.org, PUC-Rio"
AUTHORS :: "R. Ierusalimschy, L. H. de Figueiredo & W. Celes"
/* mark for precompiled code ('<esc>Lua') */
SIGNATURE :: "\x1bLua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
MULTRET :: -1
REGISTRYINDEX :: -10000
ENVIRONINDEX :: -10001
GLOBALSINDEX :: -10002
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
** (It must fit into max(size_t)/32.)
*/
MAXSTACK :: 1000000 when size_of(rawptr) == 4 else 15000
/*
@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
** a Lua state with very fast access.
** CHANGE it if you need a different size.
*/
EXTRASPACE :: size_of(rawptr)
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@@ of a function in debug information.
** CHANGE it if you want a different size.
*/
IDSIZE :: 60
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
*/
L_BUFFERSIZE :: c.int(16 * size_of(rawptr) * size_of(Number))
MAXALIGNVAL :: max(align_of(Number), align_of(f64), align_of(rawptr), align_of(Integer), align_of(c.long))
Status :: enum c.int {
OK = 0,
YIELD = 1,
ERRRUN = 2,
ERRSYNTAX = 3,
ERRMEM = 4,
ERRERR = 5,
ERRFILE = 6,
}
/* thread status */
OK :: Status.OK
YIELD :: Status.YIELD
ERRRUN :: Status.ERRRUN
ERRSYNTAX :: Status.ERRSYNTAX
ERRMEM :: Status.ERRMEM
ERRERR :: Status.ERRERR
ERRFILE :: Status.ERRFILE
/*
** basic types
*/
Type :: enum c.int {
NONE = -1,
NIL = 0,
BOOLEAN = 1,
LIGHTUSERDATA = 2,
NUMBER = 3,
STRING = 4,
TABLE = 5,
FUNCTION = 6,
USERDATA = 7,
THREAD = 8,
}
TNONE :: Type.NONE
TNIL :: Type.NIL
TBOOLEAN :: Type.BOOLEAN
TLIGHTUSERDATA :: Type.LIGHTUSERDATA
TNUMBER :: Type.NUMBER
TSTRING :: Type.STRING
TTABLE :: Type.TABLE
TFUNCTION :: Type.FUNCTION
TUSERDATA :: Type.USERDATA
TTHREAD :: Type.THREAD
NUMTYPES :: 9
CompareOp :: enum c.int {
EQ = 0,
LT = 1,
LE = 2,
}
OPEQ :: CompareOp.EQ
OPLT :: CompareOp.LT
OPLE :: CompareOp.LE
/* minimum Lua stack available to a C function */
MINSTACK :: 20
/* type of numbers in Lua */
Number :: distinct (f32 when size_of(uintptr) == 4 else f64)
/* type for integer functions */
Integer :: distinct (i32 when size_of(uintptr) == 4 else i64)
/*
** Type for C functions registered with Lua
*/
CFunction :: #type proc "c" (L: ^State) -> c.int
/*
** Type for functions that read/write blocks when loading/dumping Lua chunks
*/
Reader :: #type proc "c" (L: ^State, ud: rawptr, sz: ^c.size_t) -> cstring
Writer :: #type proc "c" (L: ^State, p: rawptr, sz: ^c.size_t, ud: rawptr) -> c.int
/*
** Type for memory-allocation functions
*/
Alloc :: #type proc "c" (ud: rawptr, ptr: rawptr, osize, nsize: c.size_t) -> rawptr
GCWhat :: enum c.int {
STOP = 0,
RESTART = 1,
COLLECT = 2,
COUNT = 3,
COUNTB = 4,
STEP = 5,
SETPAUSE = 6,
SETSTEPMUL = 7,
}
GCSTOP :: GCWhat.STOP
GCRESTART :: GCWhat.RESTART
GCCOLLECT :: GCWhat.COLLECT
GCCOUNT :: GCWhat.COUNT
GCCOUNTB :: GCWhat.COUNTB
GCSTEP :: GCWhat.STEP
GCSETPAUSE :: GCWhat.SETPAUSE
GCSETSTEPMUL :: GCWhat.SETSTEPMUL
/*
** Event codes
*/
HookEvent :: enum c.int {
CALL = 0,
RET = 1,
LINE = 2,
COUNT = 3,
TAILRET = 4,
}
HOOKCALL :: HookEvent.CALL
HOOKRET :: HookEvent.RET
HOOKLINE :: HookEvent.LINE
HOOKCOUNT :: HookEvent.COUNT
HOOKTAILRET :: HookEvent.TAILRET
/*
** Event masks
*/
HookMask :: distinct bit_set[HookEvent; c.int]
MASKCALL :: HookMask{.CALL}
MASKRET :: HookMask{.RET}
MASKLINE :: HookMask{.LINE}
MASKCOUNT :: HookMask{.COUNT}
/* activation record */
Debug :: struct {
event: HookEvent,
name: cstring, /* (n) */
namewhat: cstring, /* (n) 'global', 'local', 'field', 'method' */
what: cstring, /* (S) 'Lua', 'C', 'main', 'tail' */
source: cstring, /* (S) */
currentline: c.int, /* (l) */
nups: c.int, /* (u) number of upvalues */
linedefined: c.int, /* (S) */
lastlinedefined: c.int, /* (S) */
short_src: [IDSIZE]u8 `fmt:"s"`, /* (S) */
/* private part */
i_ci: c.int, /* active function */
}
/* Functions to be called by the debugger in specific events */
Hook :: #type proc "c" (L: ^State, ar: ^Debug)
State :: struct {} // opaque data type
@(link_prefix="lua_")
@(default_calling_convention="c")
foreign lib {
/*
** RCS ident string
*/
ident: [^]u8 // TODO(bill): is this correct?
/*
** state manipulation
*/
newstate :: proc(f: Alloc, ud: rawptr) -> ^State ---
close :: proc(L: ^State) ---
newthread :: proc(L: ^State) -> ^State ---
atpanic :: proc(L: ^State, panicf: CFunction) -> CFunction ---
/*
** basic stack manipulation
*/
gettop :: proc (L: ^State) -> c.int ---
settop :: proc (L: ^State, idx: c.int) ---
pushvalue :: proc (L: ^State, idx: c.int) ---
remove :: proc (L: ^State, idx: c.int) ---
insert :: proc (L: ^State, idx: c.int) ---
replace :: proc (L: ^State, idx: c.int) ---
checkstack :: proc (L: ^State, sz: c.int) -> c.int ---
xmove :: proc(from, to: ^State, n: c.int) ---
/*
** access functions (stack -> C)
*/
isnumber :: proc(L: ^State, idx: c.int) -> b32 ---
isstring :: proc(L: ^State, idx: c.int) -> b32 ---
iscfunction :: proc(L: ^State, idx: c.int) -> b32 ---
isinteger :: proc(L: ^State, idx: c.int) -> b32 ---
isuserdata :: proc(L: ^State, idx: c.int) -> b32 ---
type :: proc(L: ^State, idx: c.int) -> Type ---
typename :: proc(L: ^State, tp: Type) -> cstring ---
equal :: proc(L: ^State, idx1, idx2: c.int) -> b32 ---
rawequal :: proc(L: ^State, idx1, idx2: c.int) -> b32 ---
lessthan :: proc(L: ^State, idx1, idx2: c.int) -> b32 ---
toboolean :: proc(L: ^State, idx: c.int) -> b32 ---
tolstring :: proc(L: ^State, idx: c.int, len: ^c.size_t) -> cstring ---
objlen :: proc(L: ^State, idx: c.int) -> c.size_t ---
tocfunction :: proc(L: ^State, idx: c.int) -> CFunction ---
touserdata :: proc(L: ^State, idx: c.int) -> rawptr ---
tothread :: proc(L: ^State, idx: c.int) -> ^State ---
topointer :: proc(L: ^State, idx: c.int) -> rawptr ---
/*
** push functions (C -> stack)
*/
pushnil :: proc(L: ^State) ---
pushnumber :: proc(L: ^State, n: Number) ---
pushinteger :: proc(L: ^State, n: Integer) ---
pushlstring :: proc(L: ^State, s: cstring, l: c.size_t) ---
pushstring :: proc(L: ^State, s: cstring) ---
pushvfstring :: proc(L: ^State, fmt: cstring, argp: c.va_list) -> cstring ---
pushfstring :: proc(L: ^State, fmt: cstring, #c_vararg args: ..any) -> cstring ---
pushcclosure :: proc(L: ^State, fn: CFunction, n: c.int) ---
pushboolean :: proc(L: ^State, b: b32) ---
pushlightuserdata :: proc(L: ^State, p: rawptr) ---
pushthread :: proc(L: ^State) -> Status ---
/*
** get functions (Lua -> stack)
*/
gettable :: proc(L: ^State, idx: c.int) ---
getfield :: proc(L: ^State, idx: c.int, k: cstring) ---
geti :: proc(L: ^State, idx: c.int, n: Integer) ---
rawget :: proc(L: ^State, idx: c.int) ---
rawgeti :: proc(L: ^State, idx: c.int, n: Integer) ---
rawgetp :: proc(L: ^State, idx: c.int, p: rawptr) ---
createtable :: proc(L: ^State, narr, nrec: c.int) ---
newuserdata :: proc(L: ^State, sz: c.size_t) -> rawptr ---
getmetatable :: proc(L: ^State, objindex: c.int) -> c.int ---
getfenv :: proc(L: ^State, idx: c.int) ---
/*
** set functions (stack -> Lua)
*/
settable :: proc(L: ^State, idx: c.int) ---
setfield :: proc(L: ^State, idx: c.int, k: cstring) ---
rawset :: proc(L: ^State, idx: c.int) ---
rawseti :: proc(L: ^State, idx: c.int, n: c.int) ---
rawsetp :: proc(L: ^State, idx: c.int, p: rawptr) ---
setmetatable :: proc(L: ^State, objindex: c.int) -> c.int ---
setfenv :: proc(L: ^State, idx: c.int) -> c.int ---
/*
** 'load' and 'call' functions (load and run Lua code)
*/
call :: proc(L: ^State, nargs, nresults: c.int) ---
getctx :: proc(L: ^State, ctx: ^c.int) -> c.int ---
pcall :: proc(L: ^State, nargs, nresults: c.int, errfunc: c.int) -> c.int ---
cpcall :: proc(L: ^State, func: CFunction, ud: rawptr) -> c.int ---
load :: proc(L: ^State, reader: Reader, dt: rawptr,
chunkname: cstring) -> Status ---
dump :: proc(L: ^State, writer: Writer, data: rawptr) -> Status ---
/*
** coroutine functions
*/
yield :: proc(L: ^State, nresults: c.int) -> Status ---
resume :: proc(L: ^State, narg: c.int) -> Status ---
status :: proc(L: ^State) -> Status ---
/*
** garbage-collection function and options
*/
gc :: proc(L: ^State, what: GCWhat, data: c.int) -> c.int ---
/*
** miscellaneous functions
*/
error :: proc(L: ^State) -> Status ---
next :: proc(L: ^State, idx: c.int) -> c.int ---
concat :: proc(L: ^State, n: c.int) ---
len :: proc(L: ^State, idx: c.int) ---
getallocf :: proc(L: State, ud: ^rawptr) -> Alloc ---
setallocf :: proc(L: ^State, f: Alloc, ud: rawptr) ---
/*
** {======================================================================
** Debug API
** =======================================================================
*/
getstack :: proc(L: ^State, level: c.int, ar: ^Debug) -> c.int ---
getinfo :: proc(L: ^State, what: cstring, ar: ^Debug) -> c.int ---
getlocal :: proc(L: ^State, ar: ^Debug, n: c.int) -> cstring ---
setlocal :: proc(L: ^State, ar: ^Debug, n: c.int) -> cstring ---
getupvalue :: proc(L: ^State, funcindex: c.int, n: c.int) -> cstring ---
setupvalue :: proc(L: ^State, funcindex: c.int, n: c.int) -> cstring ---
sethook :: proc(L: ^State, func: Hook, mask: HookMask, count: c.int) -> c.int ---
gethook :: proc(L: ^State) -> Hook ---
gethookmask :: proc(L: ^State) -> HookMask ---
gethookcount :: proc(L: ^State) -> c.int ---
/* }============================================================== */
}
COLIBNAME :: "coroutine"
TABLIBNAME :: "table"
IOLIBNAME :: "io"
OSLIBNAME :: "os"
STRLIBNAME :: "string"
UTF8LIBNAME :: "utf8"
MATHLIBNAME :: "math"
DBLIBNAME :: "debug"
LOADLIBNAME :: "package"
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
open_base :: proc(L: ^State) -> c.int ---
open_table :: proc(L: ^State) -> c.int ---
open_io :: proc(L: ^State) -> c.int ---
open_os :: proc(L: ^State) -> c.int ---
open_string :: proc(L: ^State) -> c.int ---
open_utf8 :: proc(L: ^State) -> c.int ---
open_math :: proc(L: ^State) -> c.int ---
open_debug :: proc(L: ^State) -> c.int ---
open_package :: proc(L: ^State) -> c.int ---
/* open all previous libraries */
L_openlibs :: proc(L: ^State) ---
}
GNAME :: "_G"
L_Reg :: struct {
name: cstring,
func: CFunction,
}
/* predefined references */
NOREF :: -2
REFNIL :: -1
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
L_openlib :: proc(L: ^State, libname: cstring, l: [^]L_Reg, nup: c.int) ---
L_register :: proc(L: ^State, libname: cstring, l: ^L_Reg) ---
L_getmetafield :: proc(L: ^State, obj: c.int, e: cstring) -> c.int ---
L_callmeta :: proc(L: ^State, obj: c.int, e: cstring) -> c.int ---
L_typeerror :: proc(L: ^State, narg: c.int, tname: cstring) -> c.int ---
L_argerror :: proc(L: ^State, numarg: c.int, extramsg: cstring) -> c.int ---
@(link_name="luaL_checklstring")
L_checkstring :: proc(L: ^State, numArg: c.int, l: ^c.size_t = nil) -> cstring ---
@(link_name="luaL_optlstring")
L_optstring :: proc(L: ^State, numArg: c.int, def: cstring, l: ^c.size_t = nil) -> cstring ---
L_checknumber :: proc(L: ^State, numArg: c.int) -> Number ---
L_optnumber :: proc(L: ^State, nArg: c.int, def: Number) -> Number ---
L_checkinteger :: proc(L: ^State, numArg: c.int) -> Integer ---
L_optinteger :: proc(L: ^State, nArg: c.int, def: Integer) -> Integer ---
L_checkstack :: proc(L: ^State, sz: c.int, msg: cstring) ---
L_checktype :: proc(L: ^State, narg: c.int, t: c.int) ---
L_checkany :: proc(L: ^State, narg: c.int) ---
L_newmetatable :: proc(L: ^State, tname: cstring) -> c.int ---
L_checkudata :: proc(L: ^State, ud: c.int, tname: cstring) -> rawptr ---
L_where :: proc(L: ^State, lvl: c.int) ---
L_error :: proc(L: ^State, fmt: cstring, #c_vararg args: ..any) -> Status ---
L_checkoption :: proc(L: ^State, narg: c.int, def: cstring, lst: [^]cstring) -> c.int ---
L_ref :: proc(L: ^State, t: c.int) -> c.int ---
L_unref :: proc(L: ^State, t: c.int, ref: c.int) ---
L_loadfile :: proc (L: ^State, filename: cstring) -> Status ---
L_loadbuffer :: proc(L: ^State, buff: [^]byte, sz: c.size_t, name: cstring) -> Status ---
L_loadstring :: proc(L: ^State, s: cstring) -> Status ---
L_newstate :: proc() -> ^State ---
L_gsub :: proc(L: ^State, s, p, r: cstring) -> cstring ---
L_findtable :: proc(L: ^State, idx: c.int, fname: cstring, szhint: c.int) -> cstring ---
}
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
L_Buffer :: struct {
p: [^]byte, /* buffer address */
lvl: c.int, /* number of strings in the stack (level) */
L: ^State,
buffer: [L_BUFFERSIZE]byte, /* initial buffer */
}
L_addchar :: #force_inline proc "c" (B: ^L_Buffer, c: byte) {
end := ([^]byte)(&B.buffer)[L_BUFFERSIZE:]
if B.p < end {
L_prepbuffer(B)
}
B.p[0] = c
B.p = B.p[1:]
}
L_putchar :: L_addchar
L_addsize :: #force_inline proc "c" (B: ^L_Buffer, s: c.size_t) -> [^]byte {
B.p = B.p[s:]
return B.p
}
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
L_buffinit :: proc(L: ^State, B: ^L_Buffer) ---
L_prepbuffer :: proc(B: ^L_Buffer) -> [^]byte ---
L_addlstring :: proc(B: ^L_Buffer, s: cstring, l: c.size_t) ---
L_addstring :: proc(B: ^L_Buffer, s: cstring) ---
L_addvalue :: proc(B: ^L_Buffer) ---
L_pushresult :: proc(B: ^L_Buffer) ---
L_pushresultsize :: proc(B: ^L_Buffer, sz: c.size_t) ---
L_buffinitsize :: proc(L: ^State, B: ^L_Buffer, sz: c.size_t) -> [^]byte ---
}
@(link_prefix="lua_")
@(default_calling_convention="c")
foreign lib {
/* hack */
setlevel :: proc(from, to: ^State) ---
}
/* }====================================================== */
/*
** {==============================================================
** some useful macros
** ===============================================================
*/
pop :: #force_inline proc "c" (L: ^State, n: c.int) {
settop(L, -n-1)
}
newtable :: #force_inline proc "c" (L: ^State) {
createtable(L, 0, 0)
}
register :: #force_inline proc "c" (L: ^State, n: cstring, f: CFunction) {
pushcfunction(L, f)
setglobal(L, n)
}
pushcfunction :: #force_inline proc "c" (L: ^State, f: CFunction) {
pushcclosure(L, f, 0)
}
strlen :: #force_inline proc "c" (L: ^State, i: c.int) -> c.size_t {
return objlen(L, i)
}
isfunction :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .FUNCTION }
istable :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .TABLE }
islightuserdata :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .LIGHTUSERDATA }
isnil :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .NIL }
isboolean :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .BOOLEAN }
isthread :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .THREAD }
isnone :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .NONE }
isnoneornil :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) <= .NIL }
pushliteral :: pushstring
setglobal :: #force_inline proc "c" (L: ^State, s: cstring) {
setfield(L, GLOBALSINDEX, s)
}
getglobal :: #force_inline proc "c" (L: ^State, s: cstring) {
getfield(L, GLOBALSINDEX, s)
}
tostring :: #force_inline proc "c" (L: ^State, i: c.int) -> cstring {
return tolstring(L, i, nil)
}
open :: newstate
getregistry :: #force_inline proc "c" (L: ^State) {
pushvalue(L, REGISTRYINDEX)
}
getgccount :: #force_inline proc "c" (L: ^State) -> c.int {
return gc(L, .COUNT, 0)
}
Chunkreader :: Reader
Chunkwriter :: Writer
L_argcheck :: #force_inline proc "c" (L: ^State, cond: bool, numarg: c.int, extramsg: cstring) {
if cond {
L_argerror(L, numarg, extramsg)
}
}
L_typename :: #force_inline proc "c" (L: ^State, i: c.int) -> cstring {
return typename(L, type(L, i))
}
L_dofile :: #force_inline proc "c" (L: ^State, s: cstring) -> c.int {
err := L_loadfile(L, s)
return pcall(L, 0, MULTRET, 0) if err == nil else c.int(err)
}
L_dostring :: #force_inline proc "c" (L: ^State, s: cstring) -> c.int {
err := L_loadstring(L, s)
return pcall(L, 0, MULTRET, 0) if err == nil else c.int(err)
}
L_getmetatable :: #force_inline proc "c" (L: ^State, n: cstring) {
getfield(L, REGISTRYINDEX, n)
}
L_opt :: #force_inline proc "c" (L: ^State, f: $F, n: c.int, d: $T) -> T where intrinsics.type_is_proc(F) {
return d if isnoneornil(L, n) else f(L, n)
}
ref :: #force_inline proc "c" (L: ^State, lock: bool) -> c.int {
if lock {
return L_ref(L, REGISTRYINDEX)
}
pushstring(L, "unlocked references are obsolete")
error(L)
return 0
}
unref :: #force_inline proc "c" (L: ^State, ref: c.int) {
L_unref(L,REGISTRYINDEX, ref)
}
getref :: #force_inline proc "c" (L: ^State, ref: Integer) {
rawgeti(L, REGISTRYINDEX, ref)
}
/* }============================================================== */

BIN
vendor/lua/5.1/windows/lua5.1.dll vendored Normal file

Binary file not shown.

BIN
vendor/lua/5.1/windows/lua5.1.dll.lib vendored Normal file

Binary file not shown.

212
vendor/lua/5.2/include/lauxlib.h vendored Normal file
View File

@@ -0,0 +1,212 @@
/*
** $Id: lauxlib.h,v 1.120.1.1 2013/04/12 18:48:47 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
#ifndef lauxlib_h
#define lauxlib_h
#include <stddef.h>
#include <stdio.h>
#include "lua.h"
/* extra error code for `luaL_load' */
#define LUA_ERRFILE (LUA_ERRERR+1)
typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;
LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver);
#define luaL_checkversion(L) luaL_checkversion_(L, LUA_VERSION_NUM)
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg,
size_t *l);
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg,
const char *def, size_t *l);
LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg);
LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def);
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg);
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg,
lua_Integer def);
LUALIB_API lua_Unsigned (luaL_checkunsigned) (lua_State *L, int numArg);
LUALIB_API lua_Unsigned (luaL_optunsigned) (lua_State *L, int numArg,
lua_Unsigned def);
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_where) (lua_State *L, int lvl);
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
const char *const lst[]);
LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
/* pre-defined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
const char *mode);
#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
const char *name, const char *mode);
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API int (luaL_len) (lua_State *L, int idx);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
const char *r);
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
const char *msg, int level);
LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
lua_CFunction openf, int glb);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define luaL_newlibtable(L,l) \
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
#define luaL_newlib(L,l) (luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
#define luaL_argcheck(L, cond,numarg,extramsg) \
((void)((cond) || luaL_argerror(L, (numarg), (extramsg))))
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_dostring(L, s) \
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
typedef struct luaL_Buffer {
char *b; /* buffer address */
size_t size; /* buffer size */
size_t n; /* number of characters in buffer */
lua_State *L;
char initb[LUAL_BUFFERSIZE]; /* initial buffer */
} luaL_Buffer;
#define luaL_addchar(B,c) \
((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
((B)->b[(B)->n++] = (c)))
#define luaL_addsize(B,s) ((B)->n += (s))
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);
LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
/* }====================================================== */
/*
** {======================================================
** File handles for IO library
** =======================================================
*/
/*
** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
** initial structure 'luaL_Stream' (it may contain other fields
** after that initial structure).
*/
#define LUA_FILEHANDLE "FILE*"
typedef struct luaL_Stream {
FILE *f; /* stream (NULL for incompletely created streams) */
lua_CFunction closef; /* to close stream (NULL for closed streams) */
} luaL_Stream;
/* }====================================================== */
/* compatibility with old module system */
#if defined(LUA_COMPAT_MODULE)
LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
int sizehint);
LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
const luaL_Reg *l, int nup);
#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
#endif
#endif

444
vendor/lua/5.2/include/lua.h vendored Normal file
View File

@@ -0,0 +1,444 @@
/*
** $Id: lua.h,v 1.285.1.4 2015/02/21 14:04:50 roberto Exp $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
*/
#ifndef lua_h
#define lua_h
#include <stdarg.h>
#include <stddef.h>
#include "luaconf.h"
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "2"
#define LUA_VERSION_NUM 502
#define LUA_VERSION_RELEASE "4"
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2015 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
/* mark for precompiled code ('<esc>Lua') */
#define LUA_SIGNATURE "\033Lua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
#define LUA_MULTRET (-1)
/*
** pseudo-indices
*/
#define LUA_REGISTRYINDEX LUAI_FIRSTPSEUDOIDX
#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
/* thread status */
#define LUA_OK 0
#define LUA_YIELD 1
#define LUA_ERRRUN 2
#define LUA_ERRSYNTAX 3
#define LUA_ERRMEM 4
#define LUA_ERRGCMM 5
#define LUA_ERRERR 6
typedef struct lua_State lua_State;
typedef int (*lua_CFunction) (lua_State *L);
/*
** functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud);
/*
** prototype for memory-allocation functions
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
** basic types
*/
#define LUA_TNONE (-1)
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TLIGHTUSERDATA 2
#define LUA_TNUMBER 3
#define LUA_TSTRING 4
#define LUA_TTABLE 5
#define LUA_TFUNCTION 6
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8
#define LUA_NUMTAGS 9
/* minimum Lua stack available to a C function */
#define LUA_MINSTACK 20
/* predefined values in the registry */
#define LUA_RIDX_MAINTHREAD 1
#define LUA_RIDX_GLOBALS 2
#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
/* type of numbers in Lua */
typedef LUA_NUMBER lua_Number;
/* type for integer functions */
typedef LUA_INTEGER lua_Integer;
/* unsigned integer type */
typedef LUA_UNSIGNED lua_Unsigned;
/*
** generic extra include file
*/
#if defined(LUA_USER_H)
#include LUA_USER_H
#endif
/*
** RCS ident string
*/
extern const char lua_ident[];
/*
** state manipulation
*/
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L);
LUA_API lua_State *(lua_newthread) (lua_State *L);
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
LUA_API const lua_Number *(lua_version) (lua_State *L);
/*
** basic stack manipulation
*/
LUA_API int (lua_absindex) (lua_State *L, int idx);
LUA_API int (lua_gettop) (lua_State *L);
LUA_API void (lua_settop) (lua_State *L, int idx);
LUA_API void (lua_pushvalue) (lua_State *L, int idx);
LUA_API void (lua_remove) (lua_State *L, int idx);
LUA_API void (lua_insert) (lua_State *L, int idx);
LUA_API void (lua_replace) (lua_State *L, int idx);
LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
LUA_API int (lua_checkstack) (lua_State *L, int sz);
LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
/*
** access functions (stack -> C)
*/
LUA_API int (lua_isnumber) (lua_State *L, int idx);
LUA_API int (lua_isstring) (lua_State *L, int idx);
LUA_API int (lua_iscfunction) (lua_State *L, int idx);
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
LUA_API int (lua_type) (lua_State *L, int idx);
LUA_API const char *(lua_typename) (lua_State *L, int tp);
LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
LUA_API lua_Unsigned (lua_tounsignedx) (lua_State *L, int idx, int *isnum);
LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
/*
** Comparison and arithmetic functions
*/
#define LUA_OPADD 0 /* ORDER TM */
#define LUA_OPSUB 1
#define LUA_OPMUL 2
#define LUA_OPDIV 3
#define LUA_OPMOD 4
#define LUA_OPPOW 5
#define LUA_OPUNM 6
LUA_API void (lua_arith) (lua_State *L, int op);
#define LUA_OPEQ 0
#define LUA_OPLT 1
#define LUA_OPLE 2
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
/*
** push functions (C -> stack)
*/
LUA_API void (lua_pushnil) (lua_State *L);
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API void (lua_pushunsigned) (lua_State *L, lua_Unsigned n);
LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t l);
LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);
/*
** get functions (Lua -> stack)
*/
LUA_API void (lua_getglobal) (lua_State *L, const char *var);
LUA_API void (lua_gettable) (lua_State *L, int idx);
LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_rawget) (lua_State *L, int idx);
LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n);
LUA_API void (lua_rawgetp) (lua_State *L, int idx, const void *p);
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
LUA_API void (lua_getuservalue) (lua_State *L, int idx);
/*
** set functions (stack -> Lua)
*/
LUA_API void (lua_setglobal) (lua_State *L, const char *var);
LUA_API void (lua_settable) (lua_State *L, int idx);
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_rawset) (lua_State *L, int idx);
LUA_API void (lua_rawseti) (lua_State *L, int idx, int n);
LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
LUA_API void (lua_setuservalue) (lua_State *L, int idx);
/*
** 'load' and 'call' functions (load and run Lua code)
*/
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
lua_CFunction k);
#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
LUA_API int (lua_getctx) (lua_State *L, int *ctx);
LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
int ctx, lua_CFunction k);
#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname,
const char *mode);
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data);
/*
** coroutine functions
*/
LUA_API int (lua_yieldk) (lua_State *L, int nresults, int ctx,
lua_CFunction k);
#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
LUA_API int (lua_status) (lua_State *L);
/*
** garbage-collection function and options
*/
#define LUA_GCSTOP 0
#define LUA_GCRESTART 1
#define LUA_GCCOLLECT 2
#define LUA_GCCOUNT 3
#define LUA_GCCOUNTB 4
#define LUA_GCSTEP 5
#define LUA_GCSETPAUSE 6
#define LUA_GCSETSTEPMUL 7
#define LUA_GCSETMAJORINC 8
#define LUA_GCISRUNNING 9
#define LUA_GCGEN 10
#define LUA_GCINC 11
LUA_API int (lua_gc) (lua_State *L, int what, int data);
/*
** miscellaneous functions
*/
LUA_API int (lua_error) (lua_State *L);
LUA_API int (lua_next) (lua_State *L, int idx);
LUA_API void (lua_concat) (lua_State *L, int n);
LUA_API void (lua_len) (lua_State *L, int idx);
LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define lua_tonumber(L,i) lua_tonumberx(L,i,NULL)
#define lua_tointeger(L,i) lua_tointegerx(L,i,NULL)
#define lua_tounsigned(L,i) lua_tounsignedx(L,i,NULL)
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
#define lua_pushliteral(L, s) \
lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)
#define lua_pushglobaltable(L) \
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
/*
** {======================================================================
** Debug API
** =======================================================================
*/
/*
** Event codes
*/
#define LUA_HOOKCALL 0
#define LUA_HOOKRET 1
#define LUA_HOOKLINE 2
#define LUA_HOOKCOUNT 3
#define LUA_HOOKTAILCALL 4
/*
** Event masks
*/
#define LUA_MASKCALL (1 << LUA_HOOKCALL)
#define LUA_MASKRET (1 << LUA_HOOKRET)
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
typedef struct lua_Debug lua_Debug; /* activation record */
/* Functions to be called by the debugger in specific events */
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
int fidx2, int n2);
LUA_API int (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook (lua_gethook) (lua_State *L);
LUA_API int (lua_gethookmask) (lua_State *L);
LUA_API int (lua_gethookcount) (lua_State *L);
struct lua_Debug {
int event;
const char *name; /* (n) */
const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
const char *source; /* (S) */
int currentline; /* (l) */
int linedefined; /* (S) */
int lastlinedefined; /* (S) */
unsigned char nups; /* (u) number of upvalues */
unsigned char nparams;/* (u) number of parameters */
char isvararg; /* (u) */
char istailcall; /* (t) */
char short_src[LUA_IDSIZE]; /* (S) */
/* private part */
struct CallInfo *i_ci; /* active function */
};
/* }====================================================================== */
/******************************************************************************
* Copyright (C) 1994-2015 Lua.org, PUC-Rio.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#endif

9
vendor/lua/5.2/include/lua.hpp vendored Normal file
View File

@@ -0,0 +1,9 @@
// lua.hpp
// Lua header files for C++
// <<extern "C">> not supplied automatically because Lua also compiles as C++
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

553
vendor/lua/5.2/include/luaconf.h vendored Normal file
View File

@@ -0,0 +1,553 @@
/*
** $Id: luaconf.h,v 1.176.1.2 2013/11/21 17:26:16 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
#ifndef lconfig_h
#define lconfig_h
#include <limits.h>
#include <stddef.h>
/*
** ==================================================================
** Search for "@@" to find all configurable definitions.
** ===================================================================
*/
/*
@@ LUA_ANSI controls the use of non-ansi features.
** CHANGE it (define it) if you want Lua to avoid the use of any
** non-ansi feature or library.
*/
#if !defined(LUA_ANSI) && defined(__STRICT_ANSI__)
#define LUA_ANSI
#endif
#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE)
#define LUA_WIN /* enable goodies for regular Windows platforms */
#endif
#if defined(LUA_WIN)
#define LUA_DL_DLL
#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
#endif
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
#define LUA_USE_READLINE /* needs some extra libraries */
#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
#define LUA_USE_LONGLONG /* assume support for long long */
#endif
#if defined(LUA_USE_MACOSX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* does not need -ldl */
#define LUA_USE_READLINE /* needs an extra library: -lreadline */
#define LUA_USE_STRTODHEX /* assume 'strtod' handles hex formats */
#define LUA_USE_AFORMAT /* assume 'printf' handles 'aA' specifiers */
#define LUA_USE_LONGLONG /* assume support for long long */
#endif
/*
@@ LUA_USE_POSIX includes all functionality listed as X/Open System
@* Interfaces Extension (XSI).
** CHANGE it (define it) if your system is XSI compatible.
*/
#if defined(LUA_USE_POSIX)
#define LUA_USE_MKSTEMP
#define LUA_USE_ISATTY
#define LUA_USE_POPEN
#define LUA_USE_ULONGJMP
#define LUA_USE_GMTIME_R
#endif
/*
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
@* Lua libraries.
@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
@* C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
** non-conventional directories.
*/
#if defined(_WIN32) /* { */
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
*/
#define LUA_LDIR "!\\lua\\"
#define LUA_CDIR "!\\"
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" ".\\?.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll;" ".\\?.dll;" \
LUA_CDIR"?52.dll;" ".\\?52.dll"
#else /* }{ */
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
#define LUA_ROOT "/usr/local/"
#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR
#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" "./?.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so;" \
LUA_CDIR"lib?52.so;" "./lib?52.so"
#endif /* } */
/*
@@ LUA_DIRSEP is the directory separator (for submodules).
** CHANGE it if your machine does not use "/" as the directory separator
** and is not Windows. (On Windows Lua automatically uses "\".)
*/
#if defined(_WIN32)
#define LUA_DIRSEP "\\"
#else
#define LUA_DIRSEP "/"
#endif
/*
@@ LUA_ENV is the name of the variable that holds the current
@@ environment, used to access global names.
** CHANGE it if you do not like this name.
*/
#define LUA_ENV "_ENV"
/*
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all auxiliary library functions.
@@ LUAMOD_API is a mark for all standard library opening functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
*/
#if defined(LUA_BUILD_AS_DLL) /* { */
#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
#define LUA_API __declspec(dllexport)
#else /* }{ */
#define LUA_API __declspec(dllimport)
#endif /* } */
#else /* }{ */
#define LUA_API extern
#endif /* } */
/* more often than not the libs go together with the core */
#define LUALIB_API LUA_API
#define LUAMOD_API LUALIB_API
/*
@@ LUAI_FUNC is a mark for all extern functions that are not to be
@* exported to outside modules.
@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
@* that are not to be exported to outside modules (LUAI_DDEF for
@* definitions and LUAI_DDEC for declarations).
** CHANGE them if you need to mark them in some special way. Elf/gcc
** (versions 3.2 and later) mark them as "hidden" to optimize access
** when Lua is compiled as a shared library. Not all elf targets support
** this attribute. Unfortunately, gcc does not offer a way to check
** whether the target offers that support, and those without support
** give a warning about it. To avoid these warnings, change to the
** default definition.
*/
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
defined(__ELF__) /* { */
#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
#define LUAI_DDEC LUAI_FUNC
#define LUAI_DDEF /* empty */
#else /* }{ */
#define LUAI_FUNC extern
#define LUAI_DDEC extern
#define LUAI_DDEF /* empty */
#endif /* } */
/*
@@ LUA_QL describes how error messages quote program elements.
** CHANGE it if you want a different appearance.
*/
#define LUA_QL(x) "'" x "'"
#define LUA_QS LUA_QL("%s")
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@* of a function in debug information.
** CHANGE it if you want a different size.
*/
#define LUA_IDSIZE 60
/*
@@ luai_writestring/luai_writeline define how 'print' prints its results.
** They are only used in libraries and the stand-alone program. (The #if
** avoids including 'stdio.h' everywhere.)
*/
#if defined(LUA_LIB) || defined(lua_c)
#include <stdio.h>
#define luai_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
#define luai_writeline() (luai_writestring("\n", 1), fflush(stdout))
#endif
/*
@@ luai_writestringerror defines how to print error messages.
** (A format string with one argument is enough for Lua...)
*/
#define luai_writestringerror(s,p) \
(fprintf(stderr, (s), (p)), fflush(stderr))
/*
@@ LUAI_MAXSHORTLEN is the maximum length for short strings, that is,
** strings that are internalized. (Cannot be smaller than reserved words
** or tags for metamethods, as these strings must be internalized;
** #("function") = 8, #("__newindex") = 10.)
*/
#define LUAI_MAXSHORTLEN 40
/*
** {==================================================================
** Compatibility with previous versions
** ===================================================================
*/
/*
@@ LUA_COMPAT_ALL controls all compatibility options.
** You can define it to get all options, or change specific options
** to fit your specific needs.
*/
#if defined(LUA_COMPAT_ALL) /* { */
/*
@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
** You can replace it with 'table.unpack'.
*/
#define LUA_COMPAT_UNPACK
/*
@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
** You can replace it with 'package.searchers'.
*/
#define LUA_COMPAT_LOADERS
/*
@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
** You can call your C function directly (with light C functions).
*/
#define lua_cpcall(L,f,u) \
(lua_pushcfunction(L, (f)), \
lua_pushlightuserdata(L,(u)), \
lua_pcall(L,1,0,0))
/*
@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
** You can rewrite 'log10(x)' as 'log(x, 10)'.
*/
#define LUA_COMPAT_LOG10
/*
@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
** library. You can rewrite 'loadstring(s)' as 'load(s)'.
*/
#define LUA_COMPAT_LOADSTRING
/*
@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
*/
#define LUA_COMPAT_MAXN
/*
@@ The following macros supply trivial compatibility for some
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
*/
#define lua_strlen(L,i) lua_rawlen(L, (i))
#define lua_objlen(L,i) lua_rawlen(L, (i))
#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
/*
@@ LUA_COMPAT_MODULE controls compatibility with previous
** module functions 'module' (Lua) and 'luaL_register' (C).
*/
#define LUA_COMPAT_MODULE
#endif /* } */
/* }================================================================== */
/*
@@ LUAI_BITSINT defines the number of bits in an int.
** CHANGE here if Lua cannot automatically detect the number of bits of
** your machine. Probably you do not need to change this.
*/
/* avoid overflows in comparison */
#if INT_MAX-20 < 32760 /* { */
#define LUAI_BITSINT 16
#elif INT_MAX > 2147483640L /* }{ */
/* int has at least 32 bits */
#define LUAI_BITSINT 32
#else /* }{ */
#error "you must define LUA_BITSINT with number of bits in an integer"
#endif /* } */
/*
@@ LUA_INT32 is a signed integer with exactly 32 bits.
@@ LUAI_UMEM is an unsigned integer big enough to count the total
@* memory used by Lua.
@@ LUAI_MEM is a signed integer big enough to count the total memory
@* used by Lua.
** CHANGE here if for some weird reason the default definitions are not
** good enough for your machine. Probably you do not need to change
** this.
*/
#if LUAI_BITSINT >= 32 /* { */
#define LUA_INT32 int
#define LUAI_UMEM size_t
#define LUAI_MEM ptrdiff_t
#else /* }{ */
/* 16-bit ints */
#define LUA_INT32 long
#define LUAI_UMEM unsigned long
#define LUAI_MEM long
#endif /* } */
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
*/
#if LUAI_BITSINT >= 32
#define LUAI_MAXSTACK 1000000
#else
#define LUAI_MAXSTACK 15000
#endif
/* reserve some space for error handling */
#define LUAI_FIRSTPSEUDOIDX (-LUAI_MAXSTACK - 1000)
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
** CHANGE it if it uses too much C-stack space.
*/
#define LUAL_BUFFERSIZE BUFSIZ
/*
** {==================================================================
@@ LUA_NUMBER is the type of numbers in Lua.
** CHANGE the following definitions only if you want to build Lua
** with a number type different from double. You may also need to
** change lua_number2int & lua_number2integer.
** ===================================================================
*/
#define LUA_NUMBER_DOUBLE
#define LUA_NUMBER double
/*
@@ LUAI_UACNUMBER is the result of an 'usual argument conversion'
@* over a number.
*/
#define LUAI_UACNUMBER double
/*
@@ LUA_NUMBER_SCAN is the format for reading numbers.
@@ LUA_NUMBER_FMT is the format for writing numbers.
@@ lua_number2str converts a number to a string.
@@ LUAI_MAXNUMBER2STR is maximum size of previous conversion.
*/
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g"
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
/*
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations
*/
#define l_mathop(x) (x)
/*
@@ lua_str2number converts a decimal numeric string to a number.
@@ lua_strx2number converts an hexadecimal numeric string to a number.
** In C99, 'strtod' does both conversions. C89, however, has no function
** to convert floating hexadecimal strings to numbers. For these
** systems, you can leave 'lua_strx2number' undefined and Lua will
** provide its own implementation.
*/
#define lua_str2number(s,p) strtod((s), (p))
#if defined(LUA_USE_STRTODHEX)
#define lua_strx2number(s,p) strtod((s), (p))
#endif
/*
@@ The luai_num* macros define the primitive operations over numbers.
*/
/* the following operations need the math library */
#if defined(lobject_c) || defined(lvm_c)
#include <math.h>
#define luai_nummod(L,a,b) ((a) - l_mathop(floor)((a)/(b))*(b))
#define luai_numpow(L,a,b) (l_mathop(pow)(a,b))
#endif
/* these are quite standard operations */
#if defined(LUA_CORE)
#define luai_numadd(L,a,b) ((a)+(b))
#define luai_numsub(L,a,b) ((a)-(b))
#define luai_nummul(L,a,b) ((a)*(b))
#define luai_numdiv(L,a,b) ((a)/(b))
#define luai_numunm(L,a) (-(a))
#define luai_numeq(a,b) ((a)==(b))
#define luai_numlt(L,a,b) ((a)<(b))
#define luai_numle(L,a,b) ((a)<=(b))
#define luai_numisnan(L,a) (!luai_numeq((a), (a)))
#endif
/*
@@ LUA_INTEGER is the integral type used by lua_pushinteger/lua_tointeger.
** CHANGE that if ptrdiff_t is not adequate on your machine. (On most
** machines, ptrdiff_t gives a good choice between int or long.)
*/
#define LUA_INTEGER ptrdiff_t
/*
@@ LUA_UNSIGNED is the integral type used by lua_pushunsigned/lua_tounsigned.
** It must have at least 32 bits.
*/
#define LUA_UNSIGNED unsigned LUA_INT32
/*
** Some tricks with doubles
*/
#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
/*
** The next definitions activate some tricks to speed up the
** conversion from doubles to integer types, mainly to LUA_UNSIGNED.
**
@@ LUA_MSASMTRICK uses Microsoft assembler to avoid clashes with a
** DirectX idiosyncrasy.
**
@@ LUA_IEEE754TRICK uses a trick that should work on any machine
** using IEEE754 with a 32-bit integer type.
**
@@ LUA_IEEELL extends the trick to LUA_INTEGER; should only be
** defined when LUA_INTEGER is a 32-bit integer.
**
@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
** (0 for little endian, 1 for big endian); if not defined, Lua will
** check it dynamically for LUA_IEEE754TRICK (but not for LUA_NANTRICK).
**
@@ LUA_NANTRICK controls the use of a trick to pack all types into
** a single double value, using NaN values to represent non-number
** values. The trick only works on 32-bit machines (ints and pointers
** are 32-bit values) with numbers represented as IEEE 754-2008 doubles
** with conventional endianess (12345678 or 87654321), in CPUs that do
** not produce signaling NaN values (all NaNs are quiet).
*/
/* Microsoft compiler on a Pentium (32 bit) ? */
#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */
#define LUA_MSASMTRICK
#define LUA_IEEEENDIAN 0
#define LUA_NANTRICK
/* pentium 32 bits? */
#elif defined(__i386__) || defined(__i386) || defined(__X86__) /* }{ */
#define LUA_IEEE754TRICK
#define LUA_IEEELL
#define LUA_IEEEENDIAN 0
#define LUA_NANTRICK
/* pentium 64 bits? */
#elif defined(__x86_64) /* }{ */
#define LUA_IEEE754TRICK
#define LUA_IEEEENDIAN 0
#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */
#define LUA_IEEE754TRICK
#define LUA_IEEEENDIAN 1
#else /* }{ */
/* assume IEEE754 and a 32-bit integer type */
#define LUA_IEEE754TRICK
#endif /* } */
#endif /* } */
/* }================================================================== */
/* =================================================================== */
/*
** Local configuration. You can use this space to add your redefinitions
** without modifying the main part of the file.
*/
#endif

55
vendor/lua/5.2/include/lualib.h vendored Normal file
View File

@@ -0,0 +1,55 @@
/*
** $Id: lualib.h,v 1.43.1.1 2013/04/12 18:48:47 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
#ifndef lualib_h
#define lualib_h
#include "lua.h"
LUAMOD_API int (luaopen_base) (lua_State *L);
#define LUA_COLIBNAME "coroutine"
LUAMOD_API int (luaopen_coroutine) (lua_State *L);
#define LUA_TABLIBNAME "table"
LUAMOD_API int (luaopen_table) (lua_State *L);
#define LUA_IOLIBNAME "io"
LUAMOD_API int (luaopen_io) (lua_State *L);
#define LUA_OSLIBNAME "os"
LUAMOD_API int (luaopen_os) (lua_State *L);
#define LUA_STRLIBNAME "string"
LUAMOD_API int (luaopen_string) (lua_State *L);
#define LUA_BITLIBNAME "bit32"
LUAMOD_API int (luaopen_bit32) (lua_State *L);
#define LUA_MATHLIBNAME "math"
LUAMOD_API int (luaopen_math) (lua_State *L);
#define LUA_DBLIBNAME "debug"
LUAMOD_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);
#if !defined(lua_assert)
#define lua_assert(x) ((void)0)
#endif
#endif

BIN
vendor/lua/5.2/linux/liblua52.a vendored Normal file

Binary file not shown.

BIN
vendor/lua/5.2/linux/liblua52.so vendored Normal file

Binary file not shown.

728
vendor/lua/5.2/lua.odin vendored Normal file
View File

@@ -0,0 +1,728 @@
package lua_5_2
import "core:intrinsics"
import "core:builtin"
import c "core:c/libc"
#assert(size_of(c.int) == size_of(b32))
when ODIN_OS == .Windows {
foreign import lib "windows/lua52dll.lib"
} else when ODIN_OS == .Linux {
foreign import lib "linux/liblua52.a"
} else {
foreign import lib "system:liblua52.a"
}
VERSION_MAJOR :: "5"
VERSION_MINOR :: "2"
VERSION_NUM :: 502
VERSION_RELEASE :: "4"
VERSION :: "Lua " + VERSION_MAJOR + "." + VERSION_MINOR
RELEASE :: VERSION + "." + VERSION_RELEASE
COPYRIGHT :: RELEASE + " Copyright (C) 1994-2015 Lua.org, PUC-Rio"
AUTHORS :: "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
/* mark for precompiled code ('<esc>Lua') */
SIGNATURE :: "\x1bLua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
MULTRET :: -1
FIRSTPSEUDOIDX :: -MAXSTACK - 1000
REGISTRYINDEX :: -FIRSTPSEUDOIDX
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
** (It must fit into max(size_t)/32.)
*/
MAXSTACK :: 1000000 when size_of(rawptr) == 4 else 15000
/*
@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
** a Lua state with very fast access.
** CHANGE it if you need a different size.
*/
EXTRASPACE :: size_of(rawptr)
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@@ of a function in debug information.
** CHANGE it if you want a different size.
*/
IDSIZE :: 60
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
*/
L_BUFFERSIZE :: c.int(16 * size_of(rawptr) * size_of(Number))
MAXALIGNVAL :: max(align_of(Number), align_of(f64), align_of(rawptr), align_of(Integer), align_of(c.long))
Status :: enum c.int {
OK = 0,
YIELD = 1,
ERRRUN = 2,
ERRSYNTAX = 3,
ERRMEM = 4,
ERRERR = 5,
ERRGCMM = 6,
ERRFILE = 7,
}
/* thread status */
OK :: Status.OK
YIELD :: Status.YIELD
ERRRUN :: Status.ERRRUN
ERRSYNTAX :: Status.ERRSYNTAX
ERRMEM :: Status.ERRMEM
ERRERR :: Status.ERRERR
ERRFILE :: Status.ERRFILE
/*
** basic types
*/
Type :: enum c.int {
NONE = -1,
NIL = 0,
BOOLEAN = 1,
LIGHTUSERDATA = 2,
NUMBER = 3,
STRING = 4,
TABLE = 5,
FUNCTION = 6,
USERDATA = 7,
THREAD = 8,
}
TNONE :: Type.NONE
TNIL :: Type.NIL
TBOOLEAN :: Type.BOOLEAN
TLIGHTUSERDATA :: Type.LIGHTUSERDATA
TNUMBER :: Type.NUMBER
TSTRING :: Type.STRING
TTABLE :: Type.TABLE
TFUNCTION :: Type.FUNCTION
TUSERDATA :: Type.USERDATA
TTHREAD :: Type.THREAD
NUMTYPES :: 9
ArithOp :: enum c.int {
ADD = 0, /* ORDER TM, ORDER OP */
SUB = 1,
MUL = 2,
DIV = 3,
MOD = 4,
POW = 5,
UNM = 6,
}
CompareOp :: enum c.int {
EQ = 0,
LT = 1,
LE = 2,
}
OPADD :: ArithOp.ADD
OPSUB :: ArithOp.SUB
OPMUL :: ArithOp.MUL
OPDIV :: ArithOp.DIV
OPMOD :: ArithOp.MOD
OPPOW :: ArithOp.POW
OPUNM :: ArithOp.UNM
OPEQ :: CompareOp.EQ
OPLT :: CompareOp.LT
OPLE :: CompareOp.LE
/* minimum Lua stack available to a C function */
MINSTACK :: 20
/* predefined values in the registry */
RIDX_MAINTHREAD :: 1
RIDX_GLOBALS :: 2
RIDX_LAST :: RIDX_GLOBALS
/* type of numbers in Lua */
Number :: distinct (f32 when size_of(uintptr) == 4 else f64)
/* type for integer functions */
Integer :: distinct (i32 when size_of(uintptr) == 4 else i64)
/* unsigned integer type */
Unsigned :: distinct (u32 when size_of(uintptr) == 4 else u64)
/*
** Type for C functions registered with Lua
*/
CFunction :: #type proc "c" (L: ^State) -> c.int
/*
** Type for functions that read/write blocks when loading/dumping Lua chunks
*/
Reader :: #type proc "c" (L: ^State, ud: rawptr, sz: ^c.size_t) -> cstring
Writer :: #type proc "c" (L: ^State, p: rawptr, sz: ^c.size_t, ud: rawptr) -> c.int
/*
** Type for memory-allocation functions
*/
Alloc :: #type proc "c" (ud: rawptr, ptr: rawptr, osize, nsize: c.size_t) -> rawptr
GCWhat :: enum c.int {
STOP = 0,
RESTART = 1,
COLLECT = 2,
COUNT = 3,
COUNTB = 4,
STEP = 5,
SETPAUSE = 6,
SETSTEPMUL = 7,
SETMAJORINC = 8,
ISRUNNING = 9,
GEN = 10,
INC = 11,
}
GCSTOP :: GCWhat.STOP
GCRESTART :: GCWhat.RESTART
GCCOLLECT :: GCWhat.COLLECT
GCCOUNT :: GCWhat.COUNT
GCCOUNTB :: GCWhat.COUNTB
GCSTEP :: GCWhat.STEP
GCSETPAUSE :: GCWhat.SETPAUSE
GCSETSTEPMUL :: GCWhat.SETSTEPMUL
GCSETMAJORINC :: GCWhat.SETMAJORINC
GCISRUNNING :: GCWhat.ISRUNNING
GCGEN :: GCWhat.GEN
GCINC :: GCWhat.INC
/*
** Event codes
*/
HookEvent :: enum c.int {
CALL = 0,
RET = 1,
LINE = 2,
COUNT = 3,
TAILCALL = 4,
}
HOOKCALL :: HookEvent.CALL
HOOKRET :: HookEvent.RET
HOOKLINE :: HookEvent.LINE
HOOKCOUNT :: HookEvent.COUNT
HOOKTAILCALL :: HookEvent.TAILCALL
/*
** Event masks
*/
HookMask :: distinct bit_set[HookEvent; c.int]
MASKCALL :: HookMask{.CALL}
MASKRET :: HookMask{.RET}
MASKLINE :: HookMask{.LINE}
MASKCOUNT :: HookMask{.COUNT}
/* activation record */
Debug :: struct {
event: HookEvent,
name: cstring, /* (n) */
namewhat: cstring, /* (n) 'global', 'local', 'field', 'method' */
what: cstring, /* (S) 'Lua', 'C', 'main', 'tail' */
source: cstring, /* (S) */
currentline: c.int, /* (l) */
linedefined: c.int, /* (S) */
lastlinedefined: c.int, /* (S) */
nups: u8, /* (u) number of upvalues */
nparams: u8, /* (u) number of parameters */
isvararg: bool, /* (u) */
istailcall: bool, /* (t) */
short_src: [IDSIZE]u8 `fmt:"s"`, /* (S) */
/* private part */
i_ci: rawptr, /* active function */
}
/* Functions to be called by the debugger in specific events */
Hook :: #type proc "c" (L: ^State, ar: ^Debug)
State :: struct {} // opaque data type
@(link_prefix="lua_")
@(default_calling_convention="c")
foreign lib {
/*
** RCS ident string
*/
ident: [^]u8 // TODO(bill): is this correct?
/*
** state manipulation
*/
newstate :: proc(f: Alloc, ud: rawptr) -> ^State ---
close :: proc(L: ^State) ---
newthread :: proc(L: ^State) -> ^State ---
atpanic :: proc(L: ^State, panicf: CFunction) -> CFunction ---
version :: proc(L: ^State) -> ^Number ---
/*
** basic stack manipulation
*/
absindex :: proc (L: ^State, idx: c.int) -> c.int ---
gettop :: proc (L: ^State) -> c.int ---
settop :: proc (L: ^State, idx: c.int) ---
pushvalue :: proc (L: ^State, idx: c.int) ---
remove :: proc (L: ^State, idx: c.int) ---
insert :: proc (L: ^State, idx: c.int) ---
replace :: proc (L: ^State, idx: c.int) ---
copy :: proc (L: ^State, fromidx, toidx: c.int) ---
checkstack :: proc (L: ^State, sz: c.int) -> c.int ---
xmove :: proc(from, to: ^State, n: c.int) ---
/*
** access functions (stack -> C)
*/
isnumber :: proc(L: ^State, idx: c.int) -> b32 ---
isstring :: proc(L: ^State, idx: c.int) -> b32 ---
iscfunction :: proc(L: ^State, idx: c.int) -> b32 ---
isinteger :: proc(L: ^State, idx: c.int) -> b32 ---
isuserdata :: proc(L: ^State, idx: c.int) -> b32 ---
type :: proc(L: ^State, idx: c.int) -> Type ---
typename :: proc(L: ^State, tp: Type) -> cstring ---
@(link_name="lua_tonumberx")
tonumber :: proc(L: ^State, idx: c.int, isnum: ^b32 = nil) -> Number ---
@(link_name="lua_tointegerx")
tointeger :: proc(L: ^State, idx: c.int, isnum: ^b32 = nil) -> Integer ---
@(link_name="lua_tounsignedx")
tounsigned :: proc(L: ^State, idx: c.int, isnum: ^b32 = nil) -> Unsigned ---
toboolean :: proc(L: ^State, idx: c.int) -> b32 ---
tolstring :: proc(L: ^State, idx: c.int, len: ^c.size_t) -> cstring ---
rawlen :: proc(L: ^State, idx: c.int) -> c.size_t ---
tocfunction :: proc(L: ^State, idx: c.int) -> CFunction ---
touserdata :: proc(L: ^State, idx: c.int) -> rawptr ---
tothread :: proc(L: ^State, idx: c.int) -> ^State ---
topointer :: proc(L: ^State, idx: c.int) -> rawptr ---
/*
** Comparison and arithmetic functions
*/
arith :: proc(L: ^State, op: ArithOp) ---
rawequal :: proc(L: ^State, idx1, idx2: c.int) -> b32 ---
compare :: proc(L: ^State, idx1, idx2: c.int, op: CompareOp) -> b32 ---
/*
** push functions (C -> stack)
*/
pushnil :: proc(L: ^State) ---
pushnumber :: proc(L: ^State, n: Number) ---
pushinteger :: proc(L: ^State, n: Integer) ---
pushunsigned :: proc(L: ^State, n: Unsigned) ---
pushlstring :: proc(L: ^State, s: cstring, l: c.size_t) -> cstring ---
pushstring :: proc(L: ^State, s: cstring) -> cstring ---
pushvfstring :: proc(L: ^State, fmt: cstring, argp: c.va_list) -> cstring ---
pushfstring :: proc(L: ^State, fmt: cstring, #c_vararg args: ..any) -> cstring ---
pushcclosure :: proc(L: ^State, fn: CFunction, n: c.int) ---
pushboolean :: proc(L: ^State, b: b32) ---
pushlightuserdata :: proc(L: ^State, p: rawptr) ---
pushthread :: proc(L: ^State) -> Status ---
/*
** get functions (Lua -> stack)
*/
getglobal :: proc(L: ^State, name: cstring) ---
gettable :: proc(L: ^State, idx: c.int) ---
getfield :: proc(L: ^State, idx: c.int, k: cstring) ---
geti :: proc(L: ^State, idx: c.int, n: Integer) ---
rawget :: proc(L: ^State, idx: c.int) ---
rawgeti :: proc(L: ^State, idx: c.int, n: Integer) ---
rawgetp :: proc(L: ^State, idx: c.int, p: rawptr) ---
createtable :: proc(L: ^State, narr, nrec: c.int) ---
newuserdata :: proc(L: ^State, sz: c.size_t) -> rawptr ---
getmetatable :: proc(L: ^State, objindex: c.int) -> c.int ---
getuservalue :: proc(L: ^State, idx: c.int) ---
/*
** set functions (stack -> Lua)
*/
setglobal :: proc(L: ^State, var: cstring) ---
settable :: proc(L: ^State, idx: c.int) ---
setfield :: proc(L: ^State, idx: c.int, k: cstring) ---
rawset :: proc(L: ^State, idx: c.int) ---
rawseti :: proc(L: ^State, idx: c.int, n: c.int) ---
rawsetp :: proc(L: ^State, idx: c.int, p: rawptr) ---
setmetatable :: proc(L: ^State, objindex: c.int) -> c.int ---
setuservalue :: proc(L: ^State, idx: c.int) -> c.int ---
/*
** 'load' and 'call' functions (load and run Lua code)
*/
@(link_name="lua_callk")
call :: proc(L: ^State, nargs, nresults: c.int, ctx: c.int = 0,
k: CFunction = nil) ---
getctx :: proc(L: ^State, ctx: ^c.int) -> c.int ---
@(link_name="lua_pcallk")
pcall :: proc(L: ^State, nargs, nresults: c.int, errfunc: c.int,
ctx: c.int = 0, k: CFunction = nil) -> c.int ---
load :: proc(L: ^State, reader: Reader, dt: rawptr,
chunkname, mode: cstring) -> Status ---
dump :: proc(L: ^State, writer: Writer, data: rawptr) -> Status ---
/*
** coroutine functions
*/
@(link_name="lua_yieldk")
yield :: proc(L: ^State, nresults: c.int, ctx: c.int = 0, k: CFunction = nil) -> Status ---
resume :: proc(L: ^State, from: ^State, narg: c.int) -> Status ---
status :: proc(L: ^State) -> Status ---
/*
** garbage-collection function and options
*/
gc :: proc(L: ^State, what: GCWhat, data: c.int) -> c.int ---
/*
** miscellaneous functions
*/
error :: proc(L: ^State) -> Status ---
next :: proc(L: ^State, idx: c.int) -> c.int ---
concat :: proc(L: ^State, n: c.int) ---
len :: proc(L: ^State, idx: c.int) ---
getallocf :: proc(L: State, ud: ^rawptr) -> Alloc ---
setallocf :: proc(L: ^State, f: Alloc, ud: rawptr) ---
/*
** {======================================================================
** Debug API
** =======================================================================
*/
getstack :: proc(L: ^State, level: c.int, ar: ^Debug) -> c.int ---
getinfo :: proc(L: ^State, what: cstring, ar: ^Debug) -> c.int ---
getlocal :: proc(L: ^State, ar: ^Debug, n: c.int) -> cstring ---
setlocal :: proc(L: ^State, ar: ^Debug, n: c.int) -> cstring ---
getupvalue :: proc(L: ^State, funcindex: c.int, n: c.int) -> cstring ---
setupvalue :: proc(L: ^State, funcindex: c.int, n: c.int) -> cstring ---
upvalueid :: proc(L: ^State, fidx, n: c.int) -> rawptr ---
upvaluejoin :: proc(L: ^State, fidx1, n1, fidx2, n2: c.int) ---
sethook :: proc(L: ^State, func: Hook, mask: HookMask, count: c.int) -> c.int ---
gethook :: proc(L: ^State) -> Hook ---
gethookmask :: proc(L: ^State) -> HookMask ---
gethookcount :: proc(L: ^State) -> c.int ---
/* }============================================================== */
}
/* version suffix for environment variable names */
VERSUFFIX :: "_" + VERSION_MAJOR + "_" + VERSION_MINOR
COLIBNAME :: "coroutine"
TABLIBNAME :: "table"
IOLIBNAME :: "io"
OSLIBNAME :: "os"
STRLIBNAME :: "string"
UTF8LIBNAME :: "utf8"
BITLIBNAME :: "bit32"
MATHLIBNAME :: "math"
DBLIBNAME :: "debug"
LOADLIBNAME :: "package"
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
open_base :: proc(L: ^State) -> c.int ---
open_coroutine :: proc(L: ^State) -> c.int ---
open_table :: proc(L: ^State) -> c.int ---
open_io :: proc(L: ^State) -> c.int ---
open_os :: proc(L: ^State) -> c.int ---
open_string :: proc(L: ^State) -> c.int ---
open_utf8 :: proc(L: ^State) -> c.int ---
open_bit32 :: proc(L: ^State) -> c.int ---
open_math :: proc(L: ^State) -> c.int ---
open_debug :: proc(L: ^State) -> c.int ---
open_package :: proc(L: ^State) -> c.int ---
/* open all previous libraries */
L_openlibs :: proc(L: ^State) ---
}
GNAME :: "_G"
L_Reg :: struct {
name: cstring,
func: CFunction,
}
/* predefined references */
NOREF :: -2
REFNIL :: -1
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
@(link_name="luaL_checkversion_")
L_checkversion :: proc(L: ^State, ver: Number = VERSION_NUM) ---
L_getmetafield :: proc(L: ^State, obj: c.int, e: cstring) -> c.int ---
L_callmeta :: proc(L: ^State, obj: c.int, e: cstring) -> c.int ---
@(link_name="luaL_tolstring")
L_tostring :: proc(L: ^State, idx: c.int, len: ^c.size_t = nil) -> cstring ---
L_argerror :: proc(L: ^State, numarg: c.int, extramsg: cstring) -> c.int ---
@(link_name="luaL_checklstring")
L_checkstring :: proc(L: ^State, numArg: c.int, l: ^c.size_t = nil) -> cstring ---
@(link_name="luaL_optlstring")
L_optstring :: proc(L: ^State, numArg: c.int, def: cstring, l: ^c.size_t = nil) -> cstring ---
L_checknumber :: proc(L: ^State, numArg: c.int) -> Number ---
L_optnumber :: proc(L: ^State, nArg: c.int, def: Number) -> Number ---
L_checkinteger :: proc(L: ^State, numArg: c.int) -> Integer ---
L_optinteger :: proc(L: ^State, nArg: c.int, def: Integer) -> Integer ---
L_checkunsigned :: proc(L: ^State, numArg: c.int) -> Unsigned ---
L_optunsigned :: proc(L: ^State, nArg: c.int, def: Unsigned) -> Unsigned ---
L_checkstack :: proc(L: ^State, sz: c.int, msg: cstring) ---
L_checktype :: proc(L: ^State, narg: c.int, t: c.int) ---
L_checkany :: proc(L: ^State, narg: c.int) ---
L_newmetatable :: proc(L: ^State, tname: cstring) -> c.int ---
L_setmetatable :: proc(L: ^State, tname: cstring) ---
L_testudata :: proc(L: ^State, ud: c.int, tname: cstring) -> rawptr ---
L_checkudata :: proc(L: ^State, ud: c.int, tname: cstring) -> rawptr ---
L_where :: proc(L: ^State, lvl: c.int) ---
L_error :: proc(L: ^State, fmt: cstring, #c_vararg args: ..any) -> Status ---
L_checkoption :: proc(L: ^State, narg: c.int, def: cstring, lst: [^]cstring) -> c.int ---
L_fileresult :: proc(L: ^State, stat: c.int, fname: cstring) -> c.int ---
L_execresult :: proc(L: ^State, stat: c.int) -> c.int ---
L_ref :: proc(L: ^State, t: c.int) -> c.int ---
L_unref :: proc(L: ^State, t: c.int, ref: c.int) ---
@(link_name="luaL_loadfilex")
L_loadfile :: proc (L: ^State, filename: cstring, mode: cstring = nil) -> Status ---
@(link_name="luaL_loadbufferx")
L_loadbuffer :: proc(L: ^State, buff: [^]byte, sz: c.size_t, name: cstring, mode: cstring = nil) -> Status ---
L_loadstring :: proc(L: ^State, s: cstring) -> Status ---
L_newstate :: proc() -> ^State ---
L_len :: proc(L: ^State, idx: c.int) -> c.int ---
L_gsub :: proc(L: ^State, s, p, r: cstring) -> cstring ---
L_setfuncs :: proc(L: ^State, l: [^]L_Reg, nup: c.int) ---
L_getsubtable :: proc(L: ^State, idx: c.int, fname: cstring) -> c.int ---
L_traceback :: proc(L: ^State, L1: ^State, msg: cstring, level: c.int) ---
L_requiref :: proc(L: ^State, modname: cstring, openf: CFunction, glb: c.int) ---
}
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
L_Buffer :: struct {
b: [^]byte, /* buffer address */
size: c.size_t, /* buffer size */
n: c.size_t, /* number of characters in buffer */
L: ^State,
initb: [L_BUFFERSIZE]byte, /* initial buffer */
}
L_addchar :: #force_inline proc "c" (B: ^L_Buffer, c: byte) {
if B.n < B.size {
L_prepbuffsize(B, 1)
}
B.b[B.n] = c
B.n += 1
}
L_addsize :: #force_inline proc "c" (B: ^L_Buffer, s: c.size_t) -> c.size_t {
B.n += s
return B.n
}
L_prepbuffer :: #force_inline proc "c" (B: ^L_Buffer) -> [^]byte {
return L_prepbuffsize(B, c.size_t(L_BUFFERSIZE))
}
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
L_buffinit :: proc(L: ^State, B: ^L_Buffer) ---
L_prepbuffsize :: proc(B: ^L_Buffer, sz: c.size_t) -> [^]byte ---
L_addlstring :: proc(B: ^L_Buffer, s: cstring, l: c.size_t) ---
L_addstring :: proc(B: ^L_Buffer, s: cstring) ---
L_addvalue :: proc(B: ^L_Buffer) ---
L_pushresult :: proc(B: ^L_Buffer) ---
L_pushresultsize :: proc(B: ^L_Buffer, sz: c.size_t) ---
L_buffinitsize :: proc(L: ^State, B: ^L_Buffer, sz: c.size_t) -> [^]byte ---
}
/* }====================================================== */
/*
** {==============================================================
** some useful macros
** ===============================================================
*/
pop :: #force_inline proc "c" (L: ^State, n: c.int) {
settop(L, -n-1)
}
newtable :: #force_inline proc "c" (L: ^State) {
createtable(L, 0, 0)
}
register :: #force_inline proc "c" (L: ^State, n: cstring, f: CFunction) {
pushcfunction(L, f)
setglobal(L, n)
}
pushcfunction :: #force_inline proc "c" (L: ^State, f: CFunction) {
pushcclosure(L, f, 0)
}
isfunction :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .FUNCTION }
istable :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .TABLE }
islightuserdata :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .LIGHTUSERDATA }
isnil :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .NIL }
isboolean :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .BOOLEAN }
isthread :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .THREAD }
isnone :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .NONE }
isnoneornil :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) <= .NIL }
pushliteral :: pushstring
pushglobaltable :: #force_inline proc "c" (L: ^State) {
rawgeti(L, REGISTRYINDEX, RIDX_GLOBALS)
}
tostring :: #force_inline proc "c" (L: ^State, i: c.int) -> cstring {
return tolstring(L, i, nil)
}
L_newlibtable :: #force_inline proc "c" (L: ^State, l: []L_Reg) {
createtable(L, 0, c.int(builtin.len(l) - 1))
}
L_newlib :: proc(L: ^State, l: []L_Reg) {
L_newlibtable(L, l)
L_setfuncs(L, raw_data(l), 0)
}
L_argcheck :: #force_inline proc "c" (L: ^State, cond: bool, numarg: c.int, extramsg: cstring) {
if cond {
L_argerror(L, numarg, extramsg)
}
}
L_typename :: #force_inline proc "c" (L: ^State, i: c.int) -> cstring {
return typename(L, type(L, i))
}
L_dofile :: #force_inline proc "c" (L: ^State, s: cstring) -> c.int {
err := L_loadfile(L, s)
return pcall(L, 0, MULTRET, 0) if err == nil else c.int(err)
}
L_dostring :: #force_inline proc "c" (L: ^State, s: cstring) -> c.int {
err := L_loadstring(L, s)
return pcall(L, 0, MULTRET, 0) if err == nil else c.int(err)
}
L_getmetatable :: #force_inline proc "c" (L: ^State, n: cstring) {
getfield(L, REGISTRYINDEX, n)
}
L_opt :: #force_inline proc "c" (L: ^State, f: $F, n: c.int, d: $T) -> T where intrinsics.type_is_proc(F) {
return d if isnoneornil(L, n) else f(L, n)
}
/* }============================================================== */

BIN
vendor/lua/5.2/windows/lua52.dll vendored Normal file

Binary file not shown.

BIN
vendor/lua/5.2/windows/lua52dll.lib vendored Normal file

Binary file not shown.

264
vendor/lua/5.3/include/lauxlib.h vendored Normal file
View File

@@ -0,0 +1,264 @@
/*
** $Id: lauxlib.h,v 1.131.1.1 2017/04/19 17:20:42 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
#ifndef lauxlib_h
#define lauxlib_h
#include <stddef.h>
#include <stdio.h>
#include "lua.h"
/* extra error code for 'luaL_loadfilex' */
#define LUA_ERRFILE (LUA_ERRERR+1)
/* key, in the registry, for table of loaded modules */
#define LUA_LOADED_TABLE "_LOADED"
/* key, in the registry, for table of preloaded loaders */
#define LUA_PRELOAD_TABLE "_PRELOAD"
typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;
#define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number))
LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);
#define luaL_checkversion(L) \
luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,
size_t *l);
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,
const char *def, size_t *l);
LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg);
LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,
lua_Integer def);
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int arg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_where) (lua_State *L, int lvl);
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,
const char *const lst[]);
LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
/* predefined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
const char *mode);
#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
const char *name, const char *mode);
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p,
const char *r);
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
const char *msg, int level);
LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
lua_CFunction openf, int glb);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define luaL_newlibtable(L,l) \
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
#define luaL_newlib(L,l) \
(luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
#define luaL_argcheck(L, cond,arg,extramsg) \
((void)((cond) || luaL_argerror(L, (arg), (extramsg))))
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_dostring(L, s) \
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
typedef struct luaL_Buffer {
char *b; /* buffer address */
size_t size; /* buffer size */
size_t n; /* number of characters in buffer */
lua_State *L;
char initb[LUAL_BUFFERSIZE]; /* initial buffer */
} luaL_Buffer;
#define luaL_addchar(B,c) \
((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
((B)->b[(B)->n++] = (c)))
#define luaL_addsize(B,s) ((B)->n += (s))
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);
LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
/* }====================================================== */
/*
** {======================================================
** File handles for IO library
** =======================================================
*/
/*
** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
** initial structure 'luaL_Stream' (it may contain other fields
** after that initial structure).
*/
#define LUA_FILEHANDLE "FILE*"
typedef struct luaL_Stream {
FILE *f; /* stream (NULL for incompletely created streams) */
lua_CFunction closef; /* to close stream (NULL for closed streams) */
} luaL_Stream;
/* }====================================================== */
/* compatibility with old module system */
#if defined(LUA_COMPAT_MODULE)
LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
int sizehint);
LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
const luaL_Reg *l, int nup);
#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
#endif
/*
** {==================================================================
** "Abstraction Layer" for basic report of messages and errors
** ===================================================================
*/
/* print a string */
#if !defined(lua_writestring)
#define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
#endif
/* print a newline and flush the output */
#if !defined(lua_writeline)
#define lua_writeline() (lua_writestring("\n", 1), fflush(stdout))
#endif
/* print an error message */
#if !defined(lua_writestringerror)
#define lua_writestringerror(s,p) \
(fprintf(stderr, (s), (p)), fflush(stderr))
#endif
/* }================================================================== */
/*
** {============================================================
** Compatibility with deprecated conversions
** =============================================================
*/
#if defined(LUA_COMPAT_APIINTCASTS)
#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
#define luaL_optunsigned(L,a,d) \
((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#endif
/* }============================================================ */
#endif

485
vendor/lua/5.3/include/lua.h vendored Normal file
View File

@@ -0,0 +1,485 @@
/*
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
*/
#ifndef lua_h
#define lua_h
#include <stdarg.h>
#include <stddef.h>
#include "luaconf.h"
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "3"
#define LUA_VERSION_NUM 503
#define LUA_VERSION_RELEASE "6"
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2020 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
/* mark for precompiled code ('<esc>Lua') */
#define LUA_SIGNATURE "\x1bLua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
#define LUA_MULTRET (-1)
/*
** Pseudo-indices
** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
** space after that to help overflow detection)
*/
#define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
/* thread status */
#define LUA_OK 0
#define LUA_YIELD 1
#define LUA_ERRRUN 2
#define LUA_ERRSYNTAX 3
#define LUA_ERRMEM 4
#define LUA_ERRGCMM 5
#define LUA_ERRERR 6
typedef struct lua_State lua_State;
/*
** basic types
*/
#define LUA_TNONE (-1)
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TLIGHTUSERDATA 2
#define LUA_TNUMBER 3
#define LUA_TSTRING 4
#define LUA_TTABLE 5
#define LUA_TFUNCTION 6
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8
#define LUA_NUMTAGS 9
/* minimum Lua stack available to a C function */
#define LUA_MINSTACK 20
/* predefined values in the registry */
#define LUA_RIDX_MAINTHREAD 1
#define LUA_RIDX_GLOBALS 2
#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
/* type of numbers in Lua */
typedef LUA_NUMBER lua_Number;
/* type for integer functions */
typedef LUA_INTEGER lua_Integer;
/* unsigned integer type */
typedef LUA_UNSIGNED lua_Unsigned;
/* type for continuation-function contexts */
typedef LUA_KCONTEXT lua_KContext;
/*
** Type for C functions registered with Lua
*/
typedef int (*lua_CFunction) (lua_State *L);
/*
** Type for continuation functions
*/
typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);
/*
** Type for functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
/*
** Type for memory-allocation functions
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
** generic extra include file
*/
#if defined(LUA_USER_H)
#include LUA_USER_H
#endif
/*
** RCS ident string
*/
extern const char lua_ident[];
/*
** state manipulation
*/
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L);
LUA_API lua_State *(lua_newthread) (lua_State *L);
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
LUA_API const lua_Number *(lua_version) (lua_State *L);
/*
** basic stack manipulation
*/
LUA_API int (lua_absindex) (lua_State *L, int idx);
LUA_API int (lua_gettop) (lua_State *L);
LUA_API void (lua_settop) (lua_State *L, int idx);
LUA_API void (lua_pushvalue) (lua_State *L, int idx);
LUA_API void (lua_rotate) (lua_State *L, int idx, int n);
LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
LUA_API int (lua_checkstack) (lua_State *L, int n);
LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
/*
** access functions (stack -> C)
*/
LUA_API int (lua_isnumber) (lua_State *L, int idx);
LUA_API int (lua_isstring) (lua_State *L, int idx);
LUA_API int (lua_iscfunction) (lua_State *L, int idx);
LUA_API int (lua_isinteger) (lua_State *L, int idx);
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
LUA_API int (lua_type) (lua_State *L, int idx);
LUA_API const char *(lua_typename) (lua_State *L, int tp);
LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API size_t (lua_rawlen) (lua_State *L, int idx);
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
/*
** Comparison and arithmetic functions
*/
#define LUA_OPADD 0 /* ORDER TM, ORDER OP */
#define LUA_OPSUB 1
#define LUA_OPMUL 2
#define LUA_OPMOD 3
#define LUA_OPPOW 4
#define LUA_OPDIV 5
#define LUA_OPIDIV 6
#define LUA_OPBAND 7
#define LUA_OPBOR 8
#define LUA_OPBXOR 9
#define LUA_OPSHL 10
#define LUA_OPSHR 11
#define LUA_OPUNM 12
#define LUA_OPBNOT 13
LUA_API void (lua_arith) (lua_State *L, int op);
#define LUA_OPEQ 0
#define LUA_OPLT 1
#define LUA_OPLE 2
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
/*
** push functions (C -> stack)
*/
LUA_API void (lua_pushnil) (lua_State *L);
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);
LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);
/*
** get functions (Lua -> stack)
*/
LUA_API int (lua_getglobal) (lua_State *L, const char *name);
LUA_API int (lua_gettable) (lua_State *L, int idx);
LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);
LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);
LUA_API int (lua_rawget) (lua_State *L, int idx);
LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz);
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
LUA_API int (lua_getuservalue) (lua_State *L, int idx);
/*
** set functions (stack -> Lua)
*/
LUA_API void (lua_setglobal) (lua_State *L, const char *name);
LUA_API void (lua_settable) (lua_State *L, int idx);
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawset) (lua_State *L, int idx);
LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
LUA_API void (lua_setuservalue) (lua_State *L, int idx);
/*
** 'load' and 'call' functions (load and run Lua code)
*/
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults,
lua_KContext ctx, lua_KFunction k);
#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
lua_KContext ctx, lua_KFunction k);
#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname, const char *mode);
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
/*
** coroutine functions
*/
LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx,
lua_KFunction k);
LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg);
LUA_API int (lua_status) (lua_State *L);
LUA_API int (lua_isyieldable) (lua_State *L);
#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
/*
** garbage-collection function and options
*/
#define LUA_GCSTOP 0
#define LUA_GCRESTART 1
#define LUA_GCCOLLECT 2
#define LUA_GCCOUNT 3
#define LUA_GCCOUNTB 4
#define LUA_GCSTEP 5
#define LUA_GCSETPAUSE 6
#define LUA_GCSETSTEPMUL 7
#define LUA_GCISRUNNING 9
LUA_API int (lua_gc) (lua_State *L, int what, int data);
/*
** miscellaneous functions
*/
LUA_API int (lua_error) (lua_State *L);
LUA_API int (lua_next) (lua_State *L, int idx);
LUA_API void (lua_concat) (lua_State *L, int n);
LUA_API void (lua_len) (lua_State *L, int idx);
LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s);
LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
/*
** {==============================================================
** some useful macros
** ===============================================================
*/
#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
#define lua_pushliteral(L, s) lua_pushstring(L, "" s)
#define lua_pushglobaltable(L) \
((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
#define lua_insert(L,idx) lua_rotate(L, (idx), 1)
#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
#define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1))
/* }============================================================== */
/*
** {==============================================================
** compatibility macros for unsigned conversions
** ===============================================================
*/
#if defined(LUA_COMPAT_APIINTCASTS)
#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
#define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is))
#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
#endif
/* }============================================================== */
/*
** {======================================================================
** Debug API
** =======================================================================
*/
/*
** Event codes
*/
#define LUA_HOOKCALL 0
#define LUA_HOOKRET 1
#define LUA_HOOKLINE 2
#define LUA_HOOKCOUNT 3
#define LUA_HOOKTAILCALL 4
/*
** Event masks
*/
#define LUA_MASKCALL (1 << LUA_HOOKCALL)
#define LUA_MASKRET (1 << LUA_HOOKRET)
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
typedef struct lua_Debug lua_Debug; /* activation record */
/* Functions to be called by the debugger in specific events */
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
int fidx2, int n2);
LUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook (lua_gethook) (lua_State *L);
LUA_API int (lua_gethookmask) (lua_State *L);
LUA_API int (lua_gethookcount) (lua_State *L);
struct lua_Debug {
int event;
const char *name; /* (n) */
const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
const char *source; /* (S) */
int currentline; /* (l) */
int linedefined; /* (S) */
int lastlinedefined; /* (S) */
unsigned char nups; /* (u) number of upvalues */
unsigned char nparams;/* (u) number of parameters */
char isvararg; /* (u) */
char istailcall; /* (t) */
char short_src[LUA_IDSIZE]; /* (S) */
/* private part */
struct CallInfo *i_ci; /* active function */
};
/* }====================================================================== */
/******************************************************************************
* Copyright (C) 1994-2020 Lua.org, PUC-Rio.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#endif

9
vendor/lua/5.3/include/lua.hpp vendored Normal file
View File

@@ -0,0 +1,9 @@
// lua.hpp
// Lua header files for C++
// <<extern "C">> not supplied automatically because Lua also compiles as C++
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

792
vendor/lua/5.3/include/luaconf.h vendored Normal file
View File

@@ -0,0 +1,792 @@
/*
** $Id: luaconf.h,v 1.259.1.1 2017/04/19 17:29:57 roberto Exp $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
#ifndef luaconf_h
#define luaconf_h
#include <limits.h>
#include <stddef.h>
/*
** ===================================================================
** Search for "@@" to find all configurable definitions.
** ===================================================================
*/
/*
** {====================================================================
** System Configuration: macros to adapt (if needed) Lua to some
** particular platform, for instance compiling it with 32-bit numbers or
** restricting it to C89.
** =====================================================================
*/
/*
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You
** can also define LUA_32BITS in the make file, but changing here you
** ensure that all software connected to Lua will be compiled with the
** same configuration.
*/
/* #define LUA_32BITS */
/*
@@ LUA_USE_C89 controls the use of non-ISO-C89 features.
** Define it if you want Lua to avoid the use of a few C99 features
** or Windows-specific features on Windows.
*/
/* #define LUA_USE_C89 */
/*
** By default, Lua on Windows use (some) specific Windows features
*/
#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)
#define LUA_USE_WINDOWS /* enable goodies for regular Windows */
#endif
#if defined(LUA_USE_WINDOWS)
#define LUA_DL_DLL /* enable support for DLL */
#define LUA_USE_C89 /* broadly, Windows is C89 */
#endif
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
#define LUA_USE_READLINE /* needs some extra libraries */
#endif
#if defined(LUA_USE_MACOSX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* MacOS does not need -ldl */
#define LUA_USE_READLINE /* needs an extra library: -lreadline */
#endif
/*
@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
** C89 ('long' and 'double'); Windows always has '__int64', so it does
** not need to use this case.
*/
#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
#define LUA_C89_NUMBERS
#endif
/*
@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'.
*/
/* avoid undefined shifts */
#if ((INT_MAX >> 15) >> 15) >= 1
#define LUAI_BITSINT 32
#else
/* 'int' always must have at least 16 bits */
#define LUAI_BITSINT 16
#endif
/*
@@ LUA_INT_TYPE defines the type for Lua integers.
@@ LUA_FLOAT_TYPE defines the type for Lua floats.
** Lua should work fine with any mix of these options (if supported
** by your C compiler). The usual configurations are 64-bit integers
** and 'double' (the default), 32-bit integers and 'float' (for
** restricted platforms), and 'long'/'double' (for C compilers not
** compliant with C99, which may not have support for 'long long').
*/
/* predefined options for LUA_INT_TYPE */
#define LUA_INT_INT 1
#define LUA_INT_LONG 2
#define LUA_INT_LONGLONG 3
/* predefined options for LUA_FLOAT_TYPE */
#define LUA_FLOAT_FLOAT 1
#define LUA_FLOAT_DOUBLE 2
#define LUA_FLOAT_LONGDOUBLE 3
#if defined(LUA_32BITS) /* { */
/*
** 32-bit integers and 'float'
*/
#if LUAI_BITSINT >= 32 /* use 'int' if big enough */
#define LUA_INT_TYPE LUA_INT_INT
#else /* otherwise use 'long' */
#define LUA_INT_TYPE LUA_INT_LONG
#endif
#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
#elif defined(LUA_C89_NUMBERS) /* }{ */
/*
** largest types available for C89 ('long' and 'double')
*/
#define LUA_INT_TYPE LUA_INT_LONG
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
#endif /* } */
/*
** default configuration for 64-bit Lua ('long long' and 'double')
*/
#if !defined(LUA_INT_TYPE)
#define LUA_INT_TYPE LUA_INT_LONGLONG
#endif
#if !defined(LUA_FLOAT_TYPE)
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
#endif
/* }================================================================== */
/*
** {==================================================================
** Configuration for Paths.
** ===================================================================
*/
/*
** LUA_PATH_SEP is the character that separates templates in a path.
** LUA_PATH_MARK is the string that marks the substitution points in a
** template.
** LUA_EXEC_DIR in a Windows path is replaced by the executable's
** directory.
*/
#define LUA_PATH_SEP ";"
#define LUA_PATH_MARK "?"
#define LUA_EXEC_DIR "!"
/*
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
** Lua libraries.
@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
** C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
** non-conventional directories.
*/
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#if defined(_WIN32) /* { */
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
*/
#define LUA_LDIR "!\\lua\\"
#define LUA_CDIR "!\\"
#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
".\\?.lua;" ".\\?\\init.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.dll;" \
LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \
LUA_CDIR"loadall.dll;" ".\\?.dll;" \
LUA_CDIR"?53.dll;" ".\\?53.dll"
#else /* }{ */
#define LUA_ROOT "/usr/local/"
#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/"
#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/"
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \
"./?.lua;" "./?/init.lua"
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so;" \
LUA_CDIR"lib?53.so;" "./lib?53.so"
#endif /* } */
/*
@@ LUA_DIRSEP is the directory separator (for submodules).
** CHANGE it if your machine does not use "/" as the directory separator
** and is not Windows. (On Windows Lua automatically uses "\".)
*/
#if defined(_WIN32)
#define LUA_DIRSEP "\\"
#else
#define LUA_DIRSEP "/"
#endif
/* }================================================================== */
/*
** {==================================================================
** Marks for exported symbols in the C code
** ===================================================================
*/
/*
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all auxiliary library functions.
@@ LUAMOD_API is a mark for all standard library opening functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
*/
#if defined(LUA_BUILD_AS_DLL) /* { */
#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
#define LUA_API __declspec(dllexport)
#else /* }{ */
#define LUA_API __declspec(dllimport)
#endif /* } */
#else /* }{ */
#define LUA_API extern
#endif /* } */
/* more often than not the libs go together with the core */
#define LUALIB_API LUA_API
#define LUAMOD_API LUALIB_API
/*
@@ LUAI_FUNC is a mark for all extern functions that are not to be
** exported to outside modules.
@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
** that are not to be exported to outside modules (LUAI_DDEF for
** definitions and LUAI_DDEC for declarations).
** CHANGE them if you need to mark them in some special way. Elf/gcc
** (versions 3.2 and later) mark them as "hidden" to optimize access
** when Lua is compiled as a shared library. Not all elf targets support
** this attribute. Unfortunately, gcc does not offer a way to check
** whether the target offers that support, and those without support
** give a warning about it. To avoid these warnings, change to the
** default definition.
*/
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
defined(__ELF__) /* { */
#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
#else /* }{ */
#define LUAI_FUNC extern
#endif /* } */
#define LUAI_DDEC LUAI_FUNC
#define LUAI_DDEF /* empty */
/* }================================================================== */
/*
** {==================================================================
** Compatibility with previous versions
** ===================================================================
*/
/*
@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2.
@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1.
** You can define it to get all options, or change specific options
** to fit your specific needs.
*/
#if defined(LUA_COMPAT_5_2) /* { */
/*
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
** functions in the mathematical library.
*/
#define LUA_COMPAT_MATHLIB
/*
@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'.
*/
#define LUA_COMPAT_BITLIB
/*
@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod.
*/
#define LUA_COMPAT_IPAIRS
/*
@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
** luaL_checkint, luaL_checklong, etc.)
*/
#define LUA_COMPAT_APIINTCASTS
#endif /* } */
#if defined(LUA_COMPAT_5_1) /* { */
/* Incompatibilities from 5.2 -> 5.3 */
#define LUA_COMPAT_MATHLIB
#define LUA_COMPAT_APIINTCASTS
/*
@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
** You can replace it with 'table.unpack'.
*/
#define LUA_COMPAT_UNPACK
/*
@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
** You can replace it with 'package.searchers'.
*/
#define LUA_COMPAT_LOADERS
/*
@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
** You can call your C function directly (with light C functions).
*/
#define lua_cpcall(L,f,u) \
(lua_pushcfunction(L, (f)), \
lua_pushlightuserdata(L,(u)), \
lua_pcall(L,1,0,0))
/*
@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
** You can rewrite 'log10(x)' as 'log(x, 10)'.
*/
#define LUA_COMPAT_LOG10
/*
@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
** library. You can rewrite 'loadstring(s)' as 'load(s)'.
*/
#define LUA_COMPAT_LOADSTRING
/*
@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
*/
#define LUA_COMPAT_MAXN
/*
@@ The following macros supply trivial compatibility for some
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
*/
#define lua_strlen(L,i) lua_rawlen(L, (i))
#define lua_objlen(L,i) lua_rawlen(L, (i))
#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
/*
@@ LUA_COMPAT_MODULE controls compatibility with previous
** module functions 'module' (Lua) and 'luaL_register' (C).
*/
#define LUA_COMPAT_MODULE
#endif /* } */
/*
@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a
@@ a float mark ('.0').
** This macro is not on by default even in compatibility mode,
** because this is not really an incompatibility.
*/
/* #define LUA_COMPAT_FLOATSTRING */
/* }================================================================== */
/*
** {==================================================================
** Configuration for Numbers.
** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
** satisfy your needs.
** ===================================================================
*/
/*
@@ LUA_NUMBER is the floating-point type used by Lua.
@@ LUAI_UACNUMBER is the result of a 'default argument promotion'
@@ over a floating number.
@@ l_mathlim(x) corrects limit name 'x' to the proper float type
** by prefixing it with one of FLT/DBL/LDBL.
@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
@@ LUA_NUMBER_FMT is the format for writing floats.
@@ lua_number2str converts a float to a string.
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
@@ l_floor takes the floor of a float.
@@ lua_str2number converts a decimal numeric string to a number.
*/
/* The following definitions are good for most cases here */
#define l_floor(x) (l_mathop(floor)(x))
#define lua_number2str(s,sz,n) \
l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))
/*
@@ lua_numbertointeger converts a float number to an integer, or
** returns 0 if float is not within the range of a lua_Integer.
** (The range comparisons are tricky because of rounding. The tests
** here assume a two-complement representation, where MININTEGER always
** has an exact representation as a float; MAXINTEGER may not have one,
** and therefore its conversion to float may have an ill-defined value.)
*/
#define lua_numbertointeger(n,p) \
((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
(n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
(*(p) = (LUA_INTEGER)(n), 1))
/* now the variable definitions */
#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */
#define LUA_NUMBER float
#define l_mathlim(n) (FLT_##n)
#define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN ""
#define LUA_NUMBER_FMT "%.7g"
#define l_mathop(op) op##f
#define lua_str2number(s,p) strtof((s), (p))
#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */
#define LUA_NUMBER long double
#define l_mathlim(n) (LDBL_##n)
#define LUAI_UACNUMBER long double
#define LUA_NUMBER_FRMLEN "L"
#define LUA_NUMBER_FMT "%.19Lg"
#define l_mathop(op) op##l
#define lua_str2number(s,p) strtold((s), (p))
#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */
#define LUA_NUMBER double
#define l_mathlim(n) (DBL_##n)
#define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN ""
#define LUA_NUMBER_FMT "%.14g"
#define l_mathop(op) op
#define lua_str2number(s,p) strtod((s), (p))
#else /* }{ */
#error "numeric float type not defined"
#endif /* } */
/*
@@ LUA_INTEGER is the integer type used by Lua.
**
@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
**
@@ LUAI_UACINT is the result of a 'default argument promotion'
@@ over a lUA_INTEGER.
@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
@@ LUA_INTEGER_FMT is the format for writing integers.
@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.
@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.
@@ lua_integer2str converts an integer to a string.
*/
/* The following definitions are good for most cases here */
#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
#define LUAI_UACINT LUA_INTEGER
#define lua_integer2str(s,sz,n) \
l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))
/*
** use LUAI_UACINT here to avoid problems with promotions (which
** can turn a comparison between unsigneds into a signed comparison)
*/
#define LUA_UNSIGNED unsigned LUAI_UACINT
/* now the variable definitions */
#if LUA_INT_TYPE == LUA_INT_INT /* { int */
#define LUA_INTEGER int
#define LUA_INTEGER_FRMLEN ""
#define LUA_MAXINTEGER INT_MAX
#define LUA_MININTEGER INT_MIN
#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */
#define LUA_INTEGER long
#define LUA_INTEGER_FRMLEN "l"
#define LUA_MAXINTEGER LONG_MAX
#define LUA_MININTEGER LONG_MIN
#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */
/* use presence of macro LLONG_MAX as proxy for C99 compliance */
#if defined(LLONG_MAX) /* { */
/* use ISO C99 stuff */
#define LUA_INTEGER long long
#define LUA_INTEGER_FRMLEN "ll"
#define LUA_MAXINTEGER LLONG_MAX
#define LUA_MININTEGER LLONG_MIN
#elif defined(LUA_USE_WINDOWS) /* }{ */
/* in Windows, can use specific Windows types */
#define LUA_INTEGER __int64
#define LUA_INTEGER_FRMLEN "I64"
#define LUA_MAXINTEGER _I64_MAX
#define LUA_MININTEGER _I64_MIN
#else /* }{ */
#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \
or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
#endif /* } */
#else /* }{ */
#error "numeric integer type not defined"
#endif /* } */
/* }================================================================== */
/*
** {==================================================================
** Dependencies with C99 and other C details
** ===================================================================
*/
/*
@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.
** (All uses in Lua have only one format item.)
*/
#if !defined(LUA_USE_C89)
#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i)
#else
#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i))
#endif
/*
@@ lua_strx2number converts an hexadecimal numeric string to a number.
** In C99, 'strtod' does that conversion. Otherwise, you can
** leave 'lua_strx2number' undefined and Lua will provide its own
** implementation.
*/
#if !defined(LUA_USE_C89)
#define lua_strx2number(s,p) lua_str2number(s,p)
#endif
/*
@@ lua_pointer2str converts a pointer to a readable string in a
** non-specified way.
*/
#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p)
/*
@@ lua_number2strx converts a float to an hexadecimal numeric string.
** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
** provide its own implementation.
*/
#if !defined(LUA_USE_C89)
#define lua_number2strx(L,b,sz,f,n) \
((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))
#endif
/*
** 'strtof' and 'opf' variants for math functions are not valid in
** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the
** availability of these variants. ('math.h' is already included in
** all files that use these macros.)
*/
#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))
#undef l_mathop /* variants not available */
#undef lua_str2number
#define l_mathop(op) (lua_Number)op /* no variant */
#define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))
#endif
/*
@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation
** functions. It must be a numerical type; Lua will use 'intptr_t' if
** available, otherwise it will use 'ptrdiff_t' (the nearest thing to
** 'intptr_t' in C89)
*/
#define LUA_KCONTEXT ptrdiff_t
#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
__STDC_VERSION__ >= 199901L
#include <stdint.h>
#if defined(INTPTR_MAX) /* even in C99 this type is optional */
#undef LUA_KCONTEXT
#define LUA_KCONTEXT intptr_t
#endif
#endif
/*
@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
** Change that if you do not want to use C locales. (Code using this
** macro must include header 'locale.h'.)
*/
#if !defined(lua_getlocaledecpoint)
#define lua_getlocaledecpoint() (localeconv()->decimal_point[0])
#endif
/* }================================================================== */
/*
** {==================================================================
** Language Variations
** =====================================================================
*/
/*
@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some
** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from
** numbers to strings. Define LUA_NOCVTS2N to turn off automatic
** coercion from strings to numbers.
*/
/* #define LUA_NOCVTN2S */
/* #define LUA_NOCVTS2N */
/*
@@ LUA_USE_APICHECK turns on several consistency checks on the C API.
** Define it as a help when debugging C code.
*/
#if defined(LUA_USE_APICHECK)
#include <assert.h>
#define luai_apicheck(l,e) assert(e)
#endif
/* }================================================================== */
/*
** {==================================================================
** Macros that affect the API and must be stable (that is, must be the
** same when you compile Lua and when you compile code that links to
** Lua). You probably do not want/need to change them.
** =====================================================================
*/
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
*/
#if LUAI_BITSINT >= 32
#define LUAI_MAXSTACK 1000000
#else
#define LUAI_MAXSTACK 15000
#endif
/*
@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
** a Lua state with very fast access.
** CHANGE it if you need a different size.
*/
#define LUA_EXTRASPACE (sizeof(void *))
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@@ of a function in debug information.
** CHANGE it if you want a different size.
*/
#define LUA_IDSIZE 60
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
** CHANGE it if it uses too much C-stack space. (For long double,
** 'string.format("%.99f", -1e4932)' needs 5034 bytes, so a
** smaller buffer would force a memory allocation for each call to
** 'string.format'.)
*/
#if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE
#define LUAL_BUFFERSIZE 8192
#else
#define LUAL_BUFFERSIZE ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))
#endif
/* }================================================================== */
/*
@@ LUA_QL describes how error messages quote program elements.
** Lua does not use these macros anymore; they are here for
** compatibility only.
*/
#define LUA_QL(x) "'" x "'"
#define LUA_QS LUA_QL("%s")
/* =================================================================== */
/*
** Local configuration. You can use this space to add your redefinitions
** without modifying the main part of the file.
*/
#endif

61
vendor/lua/5.3/include/lualib.h vendored Normal file
View File

@@ -0,0 +1,61 @@
/*
** $Id: lualib.h,v 1.45.1.1 2017/04/19 17:20:42 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
#ifndef lualib_h
#define lualib_h
#include "lua.h"
/* version suffix for environment variable names */
#define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
LUAMOD_API int (luaopen_base) (lua_State *L);
#define LUA_COLIBNAME "coroutine"
LUAMOD_API int (luaopen_coroutine) (lua_State *L);
#define LUA_TABLIBNAME "table"
LUAMOD_API int (luaopen_table) (lua_State *L);
#define LUA_IOLIBNAME "io"
LUAMOD_API int (luaopen_io) (lua_State *L);
#define LUA_OSLIBNAME "os"
LUAMOD_API int (luaopen_os) (lua_State *L);
#define LUA_STRLIBNAME "string"
LUAMOD_API int (luaopen_string) (lua_State *L);
#define LUA_UTF8LIBNAME "utf8"
LUAMOD_API int (luaopen_utf8) (lua_State *L);
#define LUA_BITLIBNAME "bit32"
LUAMOD_API int (luaopen_bit32) (lua_State *L);
#define LUA_MATHLIBNAME "math"
LUAMOD_API int (luaopen_math) (lua_State *L);
#define LUA_DBLIBNAME "debug"
LUAMOD_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);
#if !defined(lua_assert)
#define lua_assert(x) ((void)0)
#endif
#endif

BIN
vendor/lua/5.3/linux/liblua53.a vendored Normal file

Binary file not shown.

BIN
vendor/lua/5.3/linux/liblua53.so vendored Normal file

Binary file not shown.

759
vendor/lua/5.3/lua.odin vendored Normal file
View File

@@ -0,0 +1,759 @@
package lua_5_3
import "core:intrinsics"
import "core:builtin"
import c "core:c/libc"
#assert(size_of(c.int) == size_of(b32))
when ODIN_OS == .Windows {
foreign import lib "windows/lua53dll.lib"
} else when ODIN_OS == .Linux {
foreign import lib "linux/liblua53.a"
} else {
foreign import lib "system:liblua53.a"
}
VERSION_MAJOR :: "5"
VERSION_MINOR :: "3"
VERSION_NUM :: 503
VERSION_RELEASE :: "6"
VERSION :: "Lua " + VERSION_MAJOR + "." + VERSION_MINOR
RELEASE :: VERSION + "." + VERSION_RELEASE
COPYRIGHT :: RELEASE + " Copyright (C) 1994-2020 Lua.org, PUC-Rio"
AUTHORS :: "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
/* mark for precompiled code ('<esc>Lua') */
SIGNATURE :: "\x1bLua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
MULTRET :: -1
REGISTRYINDEX :: -MAXSTACK - 1000
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
** (It must fit into max(size_t)/32.)
*/
MAXSTACK :: 1000000 when size_of(rawptr) == 4 else 15000
/*
@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
** a Lua state with very fast access.
** CHANGE it if you need a different size.
*/
EXTRASPACE :: size_of(rawptr)
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@@ of a function in debug information.
** CHANGE it if you want a different size.
*/
IDSIZE :: 60
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
*/
L_BUFFERSIZE :: c.int(16 * size_of(rawptr) * size_of(Number))
MAXALIGNVAL :: max(align_of(Number), align_of(f64), align_of(rawptr), align_of(Integer), align_of(c.long))
Status :: enum c.int {
OK = 0,
YIELD = 1,
ERRRUN = 2,
ERRSYNTAX = 3,
ERRMEM = 4,
ERRERR = 5,
ERRGCMM = 6,
ERRFILE = 7,
}
/* thread status */
OK :: Status.OK
YIELD :: Status.YIELD
ERRRUN :: Status.ERRRUN
ERRSYNTAX :: Status.ERRSYNTAX
ERRMEM :: Status.ERRMEM
ERRERR :: Status.ERRERR
ERRFILE :: Status.ERRFILE
/*
** basic types
*/
Type :: enum c.int {
NONE = -1,
NIL = 0,
BOOLEAN = 1,
LIGHTUSERDATA = 2,
NUMBER = 3,
STRING = 4,
TABLE = 5,
FUNCTION = 6,
USERDATA = 7,
THREAD = 8,
}
TNONE :: Type.NONE
TNIL :: Type.NIL
TBOOLEAN :: Type.BOOLEAN
TLIGHTUSERDATA :: Type.LIGHTUSERDATA
TNUMBER :: Type.NUMBER
TSTRING :: Type.STRING
TTABLE :: Type.TABLE
TFUNCTION :: Type.FUNCTION
TUSERDATA :: Type.USERDATA
TTHREAD :: Type.THREAD
NUMTYPES :: 9
ArithOp :: enum c.int {
ADD = 0, /* ORDER TM, ORDER OP */
SUB = 1,
MUL = 2,
MOD = 3,
POW = 4,
DIV = 5,
IDIV = 6,
BAND = 7,
BOR = 8,
BXOR = 9,
SHL = 10,
SHR = 11,
UNM = 12,
BNOT = 13,
}
CompareOp :: enum c.int {
EQ = 0,
LT = 1,
LE = 2,
}
OPADD :: ArithOp.ADD
OPSUB :: ArithOp.SUB
OPMUL :: ArithOp.MUL
OPMOD :: ArithOp.MOD
OPPOW :: ArithOp.POW
OPDIV :: ArithOp.DIV
OPIDIV :: ArithOp.IDIV
OPBAND :: ArithOp.BAND
OPBOR :: ArithOp.BOR
OPBXOR :: ArithOp.BXOR
OPSHL :: ArithOp.SHL
OPSHR :: ArithOp.SHR
OPUNM :: ArithOp.UNM
OPBNOT :: ArithOp.BNOT
OPEQ :: CompareOp.EQ
OPLT :: CompareOp.LT
OPLE :: CompareOp.LE
/* minimum Lua stack available to a C function */
MINSTACK :: 20
/* predefined values in the registry */
RIDX_MAINTHREAD :: 1
RIDX_GLOBALS :: 2
RIDX_LAST :: RIDX_GLOBALS
/* type of numbers in Lua */
Number :: distinct (f32 when size_of(uintptr) == 4 else f64)
/* type for integer functions */
Integer :: distinct (i32 when size_of(uintptr) == 4 else i64)
/* unsigned integer type */
Unsigned :: distinct (u32 when size_of(uintptr) == 4 else u64)
/* type for continuation-function contexts */
KContext :: distinct int
/*
** Type for C functions registered with Lua
*/
CFunction :: #type proc "c" (L: ^State) -> c.int
/*
** Type for continuation functions
*/
KFunction :: #type proc "c" (L: ^State, status: c.int, ctx: KContext) -> c.int
/*
** Type for functions that read/write blocks when loading/dumping Lua chunks
*/
Reader :: #type proc "c" (L: ^State, ud: rawptr, sz: ^c.size_t) -> cstring
Writer :: #type proc "c" (L: ^State, p: rawptr, sz: ^c.size_t, ud: rawptr) -> c.int
/*
** Type for memory-allocation functions
*/
Alloc :: #type proc "c" (ud: rawptr, ptr: rawptr, osize, nsize: c.size_t) -> rawptr
GCWhat :: enum c.int {
STOP = 0,
RESTART = 1,
COLLECT = 2,
COUNT = 3,
COUNTB = 4,
STEP = 5,
SETPAUSE = 6,
SETSTEPMUL = 7,
ISRUNNING = 9,
}
GCSTOP :: GCWhat.STOP
GCRESTART :: GCWhat.RESTART
GCCOLLECT :: GCWhat.COLLECT
GCCOUNT :: GCWhat.COUNT
GCCOUNTB :: GCWhat.COUNTB
GCSTEP :: GCWhat.STEP
GCSETPAUSE :: GCWhat.SETPAUSE
GCSETSTEPMUL :: GCWhat.SETSTEPMUL
GCISRUNNING :: GCWhat.ISRUNNING
/*
** Event codes
*/
HookEvent :: enum c.int {
CALL = 0,
RET = 1,
LINE = 2,
COUNT = 3,
TAILCALL = 4,
}
HOOKCALL :: HookEvent.CALL
HOOKRET :: HookEvent.RET
HOOKLINE :: HookEvent.LINE
HOOKCOUNT :: HookEvent.COUNT
HOOKTAILCALL :: HookEvent.TAILCALL
/*
** Event masks
*/
HookMask :: distinct bit_set[HookEvent; c.int]
MASKCALL :: HookMask{.CALL}
MASKRET :: HookMask{.RET}
MASKLINE :: HookMask{.LINE}
MASKCOUNT :: HookMask{.COUNT}
/* activation record */
Debug :: struct {
event: HookEvent,
name: cstring, /* (n) */
namewhat: cstring, /* (n) 'global', 'local', 'field', 'method' */
what: cstring, /* (S) 'Lua', 'C', 'main', 'tail' */
source: cstring, /* (S) */
currentline: c.int, /* (l) */
linedefined: c.int, /* (S) */
lastlinedefined: c.int, /* (S) */
nups: u8, /* (u) number of upvalues */
nparams: u8, /* (u) number of parameters */
isvararg: bool, /* (u) */
istailcall: bool, /* (t) */
short_src: [IDSIZE]u8 `fmt:"s"`, /* (S) */
/* private part */
i_ci: rawptr, /* active function */
}
/* Functions to be called by the debugger in specific events */
Hook :: #type proc "c" (L: ^State, ar: ^Debug)
State :: struct {} // opaque data type
@(link_prefix="lua_")
@(default_calling_convention="c")
foreign lib {
/*
** RCS ident string
*/
ident: [^]u8 // TODO(bill): is this correct?
/*
** state manipulation
*/
newstate :: proc(f: Alloc, ud: rawptr) -> ^State ---
close :: proc(L: ^State) ---
newthread :: proc(L: ^State) -> ^State ---
atpanic :: proc(L: ^State, panicf: CFunction) -> CFunction ---
version :: proc(L: ^State) -> ^Number ---
/*
** basic stack manipulation
*/
absindex :: proc (L: ^State, idx: c.int) -> c.int ---
gettop :: proc (L: ^State) -> c.int ---
settop :: proc (L: ^State, idx: c.int) ---
pushvalue :: proc (L: ^State, idx: c.int) ---
rotate :: proc (L: ^State, idx: c.int, n: c.int) ---
copy :: proc (L: ^State, fromidx, toidx: c.int) ---
checkstack :: proc (L: ^State, n: c.int) -> c.int ---
xmove :: proc(from, to: ^State, n: c.int) ---
/*
** access functions (stack -> C)
*/
isnumber :: proc(L: ^State, idx: c.int) -> b32 ---
isstring :: proc(L: ^State, idx: c.int) -> b32 ---
iscfunction :: proc(L: ^State, idx: c.int) -> b32 ---
isinteger :: proc(L: ^State, idx: c.int) -> b32 ---
isuserdata :: proc(L: ^State, idx: c.int) -> b32 ---
type :: proc(L: ^State, idx: c.int) -> Type ---
typename :: proc(L: ^State, tp: Type) -> cstring ---
@(link_name="lua_tonumberx")
tonumber :: proc(L: ^State, idx: c.int, isnum: ^b32 = nil) -> Number ---
@(link_name="lua_tointegerx")
tointeger :: proc(L: ^State, idx: c.int, isnum: ^b32 = nil) -> Integer ---
toboolean :: proc(L: ^State, idx: c.int) -> b32 ---
tolstring :: proc(L: ^State, idx: c.int, len: ^c.size_t) -> cstring ---
rawlen :: proc(L: ^State, idx: c.int) -> c.size_t ---
tocfunction :: proc(L: ^State, idx: c.int) -> CFunction ---
touserdata :: proc(L: ^State, idx: c.int) -> rawptr ---
tothread :: proc(L: ^State, idx: c.int) -> ^State ---
topointer :: proc(L: ^State, idx: c.int) -> rawptr ---
/*
** Comparison and arithmetic functions
*/
arith :: proc(L: ^State, op: ArithOp) ---
rawequal :: proc(L: ^State, idx1, idx2: c.int) -> b32 ---
compare :: proc(L: ^State, idx1, idx2: c.int, op: CompareOp) -> b32 ---
/*
** push functions (C -> stack)
*/
pushnil :: proc(L: ^State) ---
pushnumber :: proc(L: ^State, n: Number) ---
pushinteger :: proc(L: ^State, n: Integer) ---
pushlstring :: proc(L: ^State, s: cstring, len: c.size_t) -> cstring ---
pushstring :: proc(L: ^State, s: cstring) -> cstring ---
pushvfstring :: proc(L: ^State, fmt: cstring, argp: c.va_list) -> cstring ---
pushfstring :: proc(L: ^State, fmt: cstring, #c_vararg args: ..any) -> cstring ---
pushcclosure :: proc(L: ^State, fn: CFunction, n: c.int) ---
pushboolean :: proc(L: ^State, b: b32) ---
pushlightuserdata :: proc(L: ^State, p: rawptr) ---
pushthread :: proc(L: ^State) -> Status ---
/*
** get functions (Lua -> stack)
*/
getglobal :: proc(L: ^State, name: cstring) -> c.int ---
gettable :: proc(L: ^State, idx: c.int) -> c.int ---
getfield :: proc(L: ^State, idx: c.int, k: cstring) -> c.int ---
geti :: proc(L: ^State, idx: c.int, n: Integer) -> c.int ---
rawget :: proc(L: ^State, idx: c.int) -> c.int ---
rawgeti :: proc(L: ^State, idx: c.int, n: Integer) -> c.int ---
rawgetp :: proc(L: ^State, idx: c.int, p: rawptr) -> c.int ---
createtable :: proc(L: ^State, narr, nrec: c.int) ---
newuserdata :: proc(L: ^State, sz: c.size_t) -> rawptr ---
getmetatable :: proc(L: ^State, objindex: c.int) -> c.int ---
getuservalue :: proc(L: ^State, idx: c.int) -> c.int ---
/*
** set functions (stack -> Lua)
*/
setglobal :: proc(L: ^State, name: cstring) ---
settable :: proc(L: ^State, idx: c.int) ---
setfield :: proc(L: ^State, idx: c.int, k: cstring) ---
seti :: proc(L: ^State, idx: c.int, n: Integer) ---
rawset :: proc(L: ^State, idx: c.int) ---
rawseti :: proc(L: ^State, idx: c.int, n: Integer) ---
rawsetp :: proc(L: ^State, idx: c.int, p: rawptr) ---
setmetatable :: proc(L: ^State, objindex: c.int) -> c.int ---
setuservalue :: proc(L: ^State, idx: c.int) -> c.int ---
/*
** 'load' and 'call' functions (load and run Lua code)
*/
@(link_name="lua_callk")
call :: proc(L: ^State, nargs, nresults: c.int,
ctx: KContext = 0, k: KFunction = nil) ---
@(link_name="lua_pcallk")
pcall :: proc(L: ^State, nargs, nresults: c.int, errfunc: c.int,
ctx: KContext = 0, k: KFunction = nil) -> c.int ---
load :: proc(L: ^State, reader: Reader, dt: rawptr,
chunkname, mode: cstring) -> Status ---
dump :: proc(L: ^State, writer: Writer, data: rawptr, strip: b32) -> Status ---
/*
** coroutine functions
*/
@(link_name="lua_yieldk")
yield :: proc(L: ^State, nresults: c.int, ctx: KContext = 0, k: KFunction = nil) -> Status ---
resume :: proc(L: ^State, from: ^State, narg: c.int) -> Status ---
status :: proc(L: ^State) -> Status ---
isyieldable :: proc(L: ^State) -> b32 ---
/*
** garbage-collection function and options
*/
gc :: proc(L: ^State, what: GCWhat, data: c.int) -> c.int ---
/*
** miscellaneous functions
*/
error :: proc(L: ^State) -> Status ---
next :: proc(L: ^State, idx: c.int) -> c.int ---
concat :: proc(L: ^State, n: c.int) ---
len :: proc(L: ^State, idx: c.int) ---
stringtonumber :: proc(L: ^State, s: cstring) -> c.size_t ---
getallocf :: proc(L: State, ud: ^rawptr) -> Alloc ---
setallocf :: proc(L: ^State, f: Alloc, ud: rawptr) ---
/*
** {======================================================================
** Debug API
** =======================================================================
*/
getstack :: proc(L: ^State, level: c.int, ar: ^Debug) -> c.int ---
getinfo :: proc(L: ^State, what: cstring, ar: ^Debug) -> c.int ---
getlocal :: proc(L: ^State, ar: ^Debug, n: c.int) -> cstring ---
setlocal :: proc(L: ^State, ar: ^Debug, n: c.int) -> cstring ---
getupvalue :: proc(L: ^State, funcindex: c.int, n: c.int) -> cstring ---
setupvalue :: proc(L: ^State, funcindex: c.int, n: c.int) -> cstring ---
upvalueid :: proc(L: ^State, fidx, n: c.int) -> rawptr ---
upvaluejoin :: proc(L: ^State, fidx1, n1, fidx2, n2: c.int) ---
sethook :: proc(L: ^State, func: Hook, mask: HookMask, count: c.int) ---
gethook :: proc(L: ^State) -> Hook ---
gethookmask :: proc(L: ^State) -> HookMask ---
gethookcount :: proc(L: ^State) -> c.int ---
/* }============================================================== */
}
/* version suffix for environment variable names */
VERSUFFIX :: "_" + VERSION_MAJOR + "_" + VERSION_MINOR
COLIBNAME :: "coroutine"
TABLIBNAME :: "table"
IOLIBNAME :: "io"
OSLIBNAME :: "os"
STRLIBNAME :: "string"
UTF8LIBNAME :: "utf8"
BITLIBNAME :: "bit32"
MATHLIBNAME :: "math"
DBLIBNAME :: "debug"
LOADLIBNAME :: "package"
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
open_base :: proc(L: ^State) -> c.int ---
open_coroutine :: proc(L: ^State) -> c.int ---
open_table :: proc(L: ^State) -> c.int ---
open_io :: proc(L: ^State) -> c.int ---
open_os :: proc(L: ^State) -> c.int ---
open_string :: proc(L: ^State) -> c.int ---
open_utf8 :: proc(L: ^State) -> c.int ---
open_bit32 :: proc(L: ^State) -> c.int ---
open_math :: proc(L: ^State) -> c.int ---
open_debug :: proc(L: ^State) -> c.int ---
open_package :: proc(L: ^State) -> c.int ---
/* open all previous libraries */
L_openlibs :: proc(L: ^State) ---
}
GNAME :: "_G"
/* key, in the registry, for table of loaded modules */
LOADED_TABLE :: "_LOADED"
/* key, in the registry, for table of preloaded loaders */
PRELOAD_TABLE :: "_PRELOAD"
L_Reg :: struct {
name: cstring,
func: CFunction,
}
L_NUMSIZES :: size_of(Integer)*16 + size_of(Number)
/* predefined references */
NOREF :: -2
REFNIL :: -1
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
@(link_name="luaL_checkversion_")
L_checkversion :: proc(L: ^State, ver: Number = VERSION_NUM, sz: c.size_t = L_NUMSIZES) ---
L_getmetafield :: proc(L: ^State, obj: c.int, e: cstring) -> c.int ---
L_callmeta :: proc(L: ^State, obj: c.int, e: cstring) -> c.int ---
@(link_name="luaL_tolstring")
L_tostring :: proc(L: ^State, idx: c.int, len: ^c.size_t = nil) -> cstring ---
L_argerror :: proc(L: ^State, arg: c.int, extramsg: cstring) -> c.int ---
@(link_name="luaL_checklstring")
L_checkstring :: proc(L: ^State, arg: c.int, l: ^c.size_t = nil) -> cstring ---
@(link_name="luaL_optlstring")
L_optstring :: proc(L: ^State, arg: c.int, def: cstring, l: ^c.size_t = nil) -> cstring ---
L_checknumber :: proc(L: ^State, arg: c.int) -> Number ---
L_optnumber :: proc(L: ^State, arg: c.int, def: Number) -> Number ---
L_checkinteger :: proc(L: ^State, arg: c.int) -> Integer ---
L_optinteger :: proc(L: ^State, arg: c.int, def: Integer) -> Integer ---
L_checkstack :: proc(L: ^State, sz: c.int, msg: cstring) ---
L_checktype :: proc(L: ^State, arg: c.int, t: c.int) ---
L_checkany :: proc(L: ^State, arg: c.int) ---
L_newmetatable :: proc(L: ^State, tname: cstring) -> c.int ---
L_setmetatable :: proc(L: ^State, tname: cstring) ---
L_testudata :: proc(L: ^State, ud: c.int, tname: cstring) -> rawptr ---
L_checkudata :: proc(L: ^State, ud: c.int, tname: cstring) -> rawptr ---
L_where :: proc(L: ^State, lvl: c.int) ---
L_error :: proc(L: ^State, fmt: cstring, #c_vararg args: ..any) -> Status ---
L_checkoption :: proc(L: ^State, arg: c.int, def: cstring, lst: [^]cstring) -> c.int ---
L_fileresult :: proc(L: ^State, stat: c.int, fname: cstring) -> c.int ---
L_execresult :: proc(L: ^State, stat: c.int) -> c.int ---
L_ref :: proc(L: ^State, t: c.int) -> c.int ---
L_unref :: proc(L: ^State, t: c.int, ref: c.int) ---
@(link_name="luaL_loadfilex")
L_loadfile :: proc (L: ^State, filename: cstring, mode: cstring = nil) -> Status ---
@(link_name="luaL_loadbufferx")
L_loadbuffer :: proc(L: ^State, buff: [^]byte, sz: c.size_t, name: cstring, mode: cstring = nil) -> Status ---
L_loadstring :: proc(L: ^State, s: cstring) -> Status ---
L_newstate :: proc() -> ^State ---
L_len :: proc(L: ^State, idx: c.int) -> Integer ---
L_gsub :: proc(L: ^State, s, p, r: cstring) -> cstring ---
L_setfuncs :: proc(L: ^State, l: [^]L_Reg, nup: c.int) ---
L_getsubtable :: proc(L: ^State, idx: c.int, fname: cstring) -> c.int ---
L_traceback :: proc(L: ^State, L1: ^State, msg: cstring, level: c.int) ---
L_requiref :: proc(L: ^State, modname: cstring, openf: CFunction, glb: c.int) ---
}
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
L_Buffer :: struct {
b: [^]byte, /* buffer address */
size: c.size_t, /* buffer size */
n: c.size_t, /* number of characters in buffer */
L: ^State,
initb: [L_BUFFERSIZE]byte, /* initial buffer */
}
L_addchar :: #force_inline proc "c" (B: ^L_Buffer, c: byte) {
if B.n < B.size {
L_prepbuffsize(B, 1)
}
B.b[B.n] = c
B.n += 1
}
L_addsize :: #force_inline proc "c" (B: ^L_Buffer, s: c.size_t) -> c.size_t {
B.n += s
return B.n
}
L_prepbuffer :: #force_inline proc "c" (B: ^L_Buffer) -> [^]byte {
return L_prepbuffsize(B, c.size_t(L_BUFFERSIZE))
}
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
L_buffinit :: proc(L: ^State, B: ^L_Buffer) ---
L_prepbuffsize :: proc(B: ^L_Buffer, sz: c.size_t) -> [^]byte ---
L_addlstring :: proc(B: ^L_Buffer, s: cstring, l: c.size_t) ---
L_addstring :: proc(B: ^L_Buffer, s: cstring) ---
L_addvalue :: proc(B: ^L_Buffer) ---
L_pushresult :: proc(B: ^L_Buffer) ---
L_pushresultsize :: proc(B: ^L_Buffer, sz: c.size_t) ---
L_buffinitsize :: proc(L: ^State, B: ^L_Buffer, sz: c.size_t) -> [^]byte ---
}
/* }====================================================== */
/*
** {==============================================================
** some useful macros
** ===============================================================
*/
getextraspace :: #force_inline proc "c" (L: ^State) -> rawptr {
return rawptr(([^]byte)(L)[-EXTRASPACE:])
}
pop :: #force_inline proc "c" (L: ^State, n: c.int) {
settop(L, -n-1)
}
newtable :: #force_inline proc "c" (L: ^State) {
createtable(L, 0, 0)
}
register :: #force_inline proc "c" (L: ^State, n: cstring, f: CFunction) {
pushcfunction(L, f)
setglobal(L, n)
}
pushcfunction :: #force_inline proc "c" (L: ^State, f: CFunction) {
pushcclosure(L, f, 0)
}
isfunction :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .FUNCTION }
istable :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .TABLE }
islightuserdata :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .LIGHTUSERDATA }
isnil :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .NIL }
isboolean :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .BOOLEAN }
isthread :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .THREAD }
isnone :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .NONE }
isnoneornil :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) <= .NIL }
pushliteral :: pushstring
pushglobaltable :: #force_inline proc "c" (L: ^State) {
rawgeti(L, REGISTRYINDEX, RIDX_GLOBALS)
}
tostring :: #force_inline proc "c" (L: ^State, i: c.int) -> cstring {
return tolstring(L, i, nil)
}
insert :: #force_inline proc "c" (L: ^State, idx: c.int) {
rotate(L, idx, 1)
}
remove :: #force_inline proc "c" (L: ^State, idx: c.int) {
rotate(L, idx, -1)
pop(L, 1)
}
replace :: #force_inline proc "c" (L: ^State, idx: c.int) {
copy(L, -1, idx)
pop(L, 1)
}
L_newlibtable :: #force_inline proc "c" (L: ^State, l: []L_Reg) {
createtable(L, 0, c.int(builtin.len(l) - 1))
}
L_newlib :: proc(L: ^State, l: []L_Reg) {
L_checkversion(L)
L_newlibtable(L, l)
L_setfuncs(L, raw_data(l), 0)
}
L_argcheck :: #force_inline proc "c" (L: ^State, cond: bool, arg: c.int, extramsg: cstring) {
if cond {
L_argerror(L, arg, extramsg)
}
}
L_typename :: #force_inline proc "c" (L: ^State, i: c.int) -> cstring {
return typename(L, type(L, i))
}
L_dofile :: #force_inline proc "c" (L: ^State, s: cstring) -> c.int {
err := L_loadfile(L, s)
return pcall(L, 0, MULTRET, 0) if err == nil else c.int(err)
}
L_dostring :: #force_inline proc "c" (L: ^State, s: cstring) -> c.int {
err := L_loadstring(L, s)
return pcall(L, 0, MULTRET, 0) if err == nil else c.int(err)
}
L_getmetatable :: #force_inline proc "c" (L: ^State, n: cstring) -> c.int {
return getfield(L, REGISTRYINDEX, n)
}
L_opt :: #force_inline proc "c" (L: ^State, f: $F, n: c.int, d: $T) -> T where intrinsics.type_is_proc(F) {
return d if isnoneornil(L, n) else f(L, n)
}
/* }============================================================== */

BIN
vendor/lua/5.3/windows/lua53.dll vendored Normal file

Binary file not shown.

BIN
vendor/lua/5.3/windows/lua53dll.lib vendored Normal file

Binary file not shown.

276
vendor/lua/5.4/include/lauxlib.h vendored Normal file
View File

@@ -0,0 +1,276 @@
/*
** $Id: lauxlib.h $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
#ifndef lauxlib_h
#define lauxlib_h
#include <stddef.h>
#include <stdio.h>
#include "lua.h"
/* global table */
#define LUA_GNAME "_G"
typedef struct luaL_Buffer luaL_Buffer;
/* extra error code for 'luaL_loadfilex' */
#define LUA_ERRFILE (LUA_ERRERR+1)
/* key, in the registry, for table of loaded modules */
#define LUA_LOADED_TABLE "_LOADED"
/* key, in the registry, for table of preloaded loaders */
#define LUA_PRELOAD_TABLE "_PRELOAD"
typedef struct luaL_Reg {
const char *name;
lua_CFunction func;
} luaL_Reg;
#define LUAL_NUMSIZES (sizeof(lua_Integer)*16 + sizeof(lua_Number))
LUALIB_API void (luaL_checkversion_) (lua_State *L, lua_Number ver, size_t sz);
#define luaL_checkversion(L) \
luaL_checkversion_(L, LUA_VERSION_NUM, LUAL_NUMSIZES)
LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);
LUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,
size_t *l);
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,
const char *def, size_t *l);
LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg);
LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def);
LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg);
LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg,
lua_Integer def);
LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg);
LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t);
LUALIB_API void (luaL_checkany) (lua_State *L, int arg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void (luaL_where) (lua_State *L, int lvl);
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,
const char *const lst[]);
LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
/* predefined references */
#define LUA_NOREF (-2)
#define LUA_REFNIL (-1)
LUALIB_API int (luaL_ref) (lua_State *L, int t);
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
const char *mode);
#define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL)
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
const char *name, const char *mode);
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
const char *p, const char *r);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s,
const char *p, const char *r);
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
LUALIB_API int (luaL_getsubtable) (lua_State *L, int idx, const char *fname);
LUALIB_API void (luaL_traceback) (lua_State *L, lua_State *L1,
const char *msg, int level);
LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
lua_CFunction openf, int glb);
/*
** ===============================================================
** some useful macros
** ===============================================================
*/
#define luaL_newlibtable(L,l) \
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
#define luaL_newlib(L,l) \
(luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
#define luaL_argcheck(L, cond,arg,extramsg) \
((void)((cond) || luaL_argerror(L, (arg), (extramsg))))
#define luaL_argexpected(L,cond,arg,tname) \
((void)((cond) || luaL_typeerror(L, (arg), (tname))))
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_dostring(L, s) \
(luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0))
#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n)))
#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n)))
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
/* push the value used to represent failure/error */
#define luaL_pushfail(L) lua_pushnil(L)
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
struct luaL_Buffer {
char *b; /* buffer address */
size_t size; /* buffer size */
size_t n; /* number of characters in buffer */
lua_State *L;
union {
LUAI_MAXALIGN; /* ensure maximum alignment for buffer */
char b[LUAL_BUFFERSIZE]; /* initial buffer */
} init;
};
#define luaL_bufflen(bf) ((bf)->n)
#define luaL_buffaddr(bf) ((bf)->b)
#define luaL_addchar(B,c) \
((void)((B)->n < (B)->size || luaL_prepbuffsize((B), 1)), \
((B)->b[(B)->n++] = (c)))
#define luaL_addsize(B,s) ((B)->n += (s))
#define luaL_buffsub(B,s) ((B)->n -= (s))
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s);
LUALIB_API void (luaL_addvalue) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
LUALIB_API void (luaL_pushresultsize) (luaL_Buffer *B, size_t sz);
LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz);
#define luaL_prepbuffer(B) luaL_prepbuffsize(B, LUAL_BUFFERSIZE)
/* }====================================================== */
/*
** {======================================================
** File handles for IO library
** =======================================================
*/
/*
** A file handle is a userdata with metatable 'LUA_FILEHANDLE' and
** initial structure 'luaL_Stream' (it may contain other fields
** after that initial structure).
*/
#define LUA_FILEHANDLE "FILE*"
typedef struct luaL_Stream {
FILE *f; /* stream (NULL for incompletely created streams) */
lua_CFunction closef; /* to close stream (NULL for closed streams) */
} luaL_Stream;
/* }====================================================== */
/*
** {==================================================================
** "Abstraction Layer" for basic report of messages and errors
** ===================================================================
*/
/* print a string */
#if !defined(lua_writestring)
#define lua_writestring(s,l) fwrite((s), sizeof(char), (l), stdout)
#endif
/* print a newline and flush the output */
#if !defined(lua_writeline)
#define lua_writeline() (lua_writestring("\n", 1), fflush(stdout))
#endif
/* print an error message */
#if !defined(lua_writestringerror)
#define lua_writestringerror(s,p) \
(fprintf(stderr, (s), (p)), fflush(stderr))
#endif
/* }================================================================== */
/*
** {============================================================
** Compatibility with deprecated conversions
** =============================================================
*/
#if defined(LUA_COMPAT_APIINTCASTS)
#define luaL_checkunsigned(L,a) ((lua_Unsigned)luaL_checkinteger(L,a))
#define luaL_optunsigned(L,a,d) \
((lua_Unsigned)luaL_optinteger(L,a,(lua_Integer)(d)))
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#endif
/* }============================================================ */
#endif

517
vendor/lua/5.4/include/lua.h vendored Normal file
View File

@@ -0,0 +1,517 @@
/*
** $Id: lua.h $
** Lua - A Scripting Language
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
** See Copyright Notice at the end of this file
*/
#ifndef lua_h
#define lua_h
#include <stdarg.h>
#include <stddef.h>
#include "luaconf.h"
#define LUA_VERSION_MAJOR "5"
#define LUA_VERSION_MINOR "4"
#define LUA_VERSION_RELEASE "2"
#define LUA_VERSION_NUM 504
#define LUA_VERSION_RELEASE_NUM (LUA_VERSION_NUM * 100 + 0)
#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE
#define LUA_COPYRIGHT LUA_RELEASE " Copyright (C) 1994-2020 Lua.org, PUC-Rio"
#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
/* mark for precompiled code ('<esc>Lua') */
#define LUA_SIGNATURE "\x1bLua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
#define LUA_MULTRET (-1)
/*
** Pseudo-indices
** (-LUAI_MAXSTACK is the minimum valid index; we keep some free empty
** space after that to help overflow detection)
*/
#define LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000)
#define lua_upvalueindex(i) (LUA_REGISTRYINDEX - (i))
/* thread status */
#define LUA_OK 0
#define LUA_YIELD 1
#define LUA_ERRRUN 2
#define LUA_ERRSYNTAX 3
#define LUA_ERRMEM 4
#define LUA_ERRERR 5
typedef struct lua_State lua_State;
/*
** basic types
*/
#define LUA_TNONE (-1)
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TLIGHTUSERDATA 2
#define LUA_TNUMBER 3
#define LUA_TSTRING 4
#define LUA_TTABLE 5
#define LUA_TFUNCTION 6
#define LUA_TUSERDATA 7
#define LUA_TTHREAD 8
#define LUA_NUMTYPES 9
/* minimum Lua stack available to a C function */
#define LUA_MINSTACK 20
/* predefined values in the registry */
#define LUA_RIDX_MAINTHREAD 1
#define LUA_RIDX_GLOBALS 2
#define LUA_RIDX_LAST LUA_RIDX_GLOBALS
/* type of numbers in Lua */
typedef LUA_NUMBER lua_Number;
/* type for integer functions */
typedef LUA_INTEGER lua_Integer;
/* unsigned integer type */
typedef LUA_UNSIGNED lua_Unsigned;
/* type for continuation-function contexts */
typedef LUA_KCONTEXT lua_KContext;
/*
** Type for C functions registered with Lua
*/
typedef int (*lua_CFunction) (lua_State *L);
/*
** Type for continuation functions
*/
typedef int (*lua_KFunction) (lua_State *L, int status, lua_KContext ctx);
/*
** Type for functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
typedef int (*lua_Writer) (lua_State *L, const void *p, size_t sz, void *ud);
/*
** Type for memory-allocation functions
*/
typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
/*
** Type for warning functions
*/
typedef void (*lua_WarnFunction) (void *ud, const char *msg, int tocont);
/*
** generic extra include file
*/
#if defined(LUA_USER_H)
#include LUA_USER_H
#endif
/*
** RCS ident string
*/
extern const char lua_ident[];
/*
** state manipulation
*/
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
LUA_API void (lua_close) (lua_State *L);
LUA_API lua_State *(lua_newthread) (lua_State *L);
LUA_API int (lua_resetthread) (lua_State *L);
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
LUA_API lua_Number (lua_version) (lua_State *L);
/*
** basic stack manipulation
*/
LUA_API int (lua_absindex) (lua_State *L, int idx);
LUA_API int (lua_gettop) (lua_State *L);
LUA_API void (lua_settop) (lua_State *L, int idx);
LUA_API void (lua_pushvalue) (lua_State *L, int idx);
LUA_API void (lua_rotate) (lua_State *L, int idx, int n);
LUA_API void (lua_copy) (lua_State *L, int fromidx, int toidx);
LUA_API int (lua_checkstack) (lua_State *L, int n);
LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n);
/*
** access functions (stack -> C)
*/
LUA_API int (lua_isnumber) (lua_State *L, int idx);
LUA_API int (lua_isstring) (lua_State *L, int idx);
LUA_API int (lua_iscfunction) (lua_State *L, int idx);
LUA_API int (lua_isinteger) (lua_State *L, int idx);
LUA_API int (lua_isuserdata) (lua_State *L, int idx);
LUA_API int (lua_type) (lua_State *L, int idx);
LUA_API const char *(lua_typename) (lua_State *L, int tp);
LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum);
LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum);
LUA_API int (lua_toboolean) (lua_State *L, int idx);
LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len);
LUA_API lua_Unsigned (lua_rawlen) (lua_State *L, int idx);
LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx);
LUA_API void *(lua_touserdata) (lua_State *L, int idx);
LUA_API lua_State *(lua_tothread) (lua_State *L, int idx);
LUA_API const void *(lua_topointer) (lua_State *L, int idx);
/*
** Comparison and arithmetic functions
*/
#define LUA_OPADD 0 /* ORDER TM, ORDER OP */
#define LUA_OPSUB 1
#define LUA_OPMUL 2
#define LUA_OPMOD 3
#define LUA_OPPOW 4
#define LUA_OPDIV 5
#define LUA_OPIDIV 6
#define LUA_OPBAND 7
#define LUA_OPBOR 8
#define LUA_OPBXOR 9
#define LUA_OPSHL 10
#define LUA_OPSHR 11
#define LUA_OPUNM 12
#define LUA_OPBNOT 13
LUA_API void (lua_arith) (lua_State *L, int op);
#define LUA_OPEQ 0
#define LUA_OPLT 1
#define LUA_OPLE 2
LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2);
LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op);
/*
** push functions (C -> stack)
*/
LUA_API void (lua_pushnil) (lua_State *L);
LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n);
LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n);
LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len);
LUA_API const char *(lua_pushstring) (lua_State *L, const char *s);
LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt,
va_list argp);
LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);
/*
** get functions (Lua -> stack)
*/
LUA_API int (lua_getglobal) (lua_State *L, const char *name);
LUA_API int (lua_gettable) (lua_State *L, int idx);
LUA_API int (lua_getfield) (lua_State *L, int idx, const char *k);
LUA_API int (lua_geti) (lua_State *L, int idx, lua_Integer n);
LUA_API int (lua_rawget) (lua_State *L, int idx);
LUA_API int (lua_rawgeti) (lua_State *L, int idx, lua_Integer n);
LUA_API int (lua_rawgetp) (lua_State *L, int idx, const void *p);
LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec);
LUA_API void *(lua_newuserdatauv) (lua_State *L, size_t sz, int nuvalue);
LUA_API int (lua_getmetatable) (lua_State *L, int objindex);
LUA_API int (lua_getiuservalue) (lua_State *L, int idx, int n);
/*
** set functions (stack -> Lua)
*/
LUA_API void (lua_setglobal) (lua_State *L, const char *name);
LUA_API void (lua_settable) (lua_State *L, int idx);
LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k);
LUA_API void (lua_seti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawset) (lua_State *L, int idx);
LUA_API void (lua_rawseti) (lua_State *L, int idx, lua_Integer n);
LUA_API void (lua_rawsetp) (lua_State *L, int idx, const void *p);
LUA_API int (lua_setmetatable) (lua_State *L, int objindex);
LUA_API int (lua_setiuservalue) (lua_State *L, int idx, int n);
/*
** 'load' and 'call' functions (load and run Lua code)
*/
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults,
lua_KContext ctx, lua_KFunction k);
#define lua_call(L,n,r) lua_callk(L, (n), (r), 0, NULL)
LUA_API int (lua_pcallk) (lua_State *L, int nargs, int nresults, int errfunc,
lua_KContext ctx, lua_KFunction k);
#define lua_pcall(L,n,r,f) lua_pcallk(L, (n), (r), (f), 0, NULL)
LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt,
const char *chunkname, const char *mode);
LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data, int strip);
/*
** coroutine functions
*/
LUA_API int (lua_yieldk) (lua_State *L, int nresults, lua_KContext ctx,
lua_KFunction k);
LUA_API int (lua_resume) (lua_State *L, lua_State *from, int narg,
int *nres);
LUA_API int (lua_status) (lua_State *L);
LUA_API int (lua_isyieldable) (lua_State *L);
#define lua_yield(L,n) lua_yieldk(L, (n), 0, NULL)
/*
** Warning-related functions
*/
LUA_API void (lua_setwarnf) (lua_State *L, lua_WarnFunction f, void *ud);
LUA_API void (lua_warning) (lua_State *L, const char *msg, int tocont);
/*
** garbage-collection function and options
*/
#define LUA_GCSTOP 0
#define LUA_GCRESTART 1
#define LUA_GCCOLLECT 2
#define LUA_GCCOUNT 3
#define LUA_GCCOUNTB 4
#define LUA_GCSTEP 5
#define LUA_GCSETPAUSE 6
#define LUA_GCSETSTEPMUL 7
#define LUA_GCISRUNNING 9
#define LUA_GCGEN 10
#define LUA_GCINC 11
LUA_API int (lua_gc) (lua_State *L, int what, ...);
/*
** miscellaneous functions
*/
LUA_API int (lua_error) (lua_State *L);
LUA_API int (lua_next) (lua_State *L, int idx);
LUA_API void (lua_concat) (lua_State *L, int n);
LUA_API void (lua_len) (lua_State *L, int idx);
LUA_API size_t (lua_stringtonumber) (lua_State *L, const char *s);
LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud);
LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
LUA_API void (lua_toclose) (lua_State *L, int idx);
/*
** {==============================================================
** some useful macros
** ===============================================================
*/
#define lua_getextraspace(L) ((void *)((char *)(L) - LUA_EXTRASPACE))
#define lua_tonumber(L,i) lua_tonumberx(L,(i),NULL)
#define lua_tointeger(L,i) lua_tointegerx(L,(i),NULL)
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_newtable(L) lua_createtable(L, 0, 0)
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION)
#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE)
#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA)
#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL)
#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN)
#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD)
#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE)
#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0)
#define lua_pushliteral(L, s) lua_pushstring(L, "" s)
#define lua_pushglobaltable(L) \
((void)lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS))
#define lua_tostring(L,i) lua_tolstring(L, (i), NULL)
#define lua_insert(L,idx) lua_rotate(L, (idx), 1)
#define lua_remove(L,idx) (lua_rotate(L, (idx), -1), lua_pop(L, 1))
#define lua_replace(L,idx) (lua_copy(L, -1, (idx)), lua_pop(L, 1))
/* }============================================================== */
/*
** {==============================================================
** compatibility macros
** ===============================================================
*/
#if defined(LUA_COMPAT_APIINTCASTS)
#define lua_pushunsigned(L,n) lua_pushinteger(L, (lua_Integer)(n))
#define lua_tounsignedx(L,i,is) ((lua_Unsigned)lua_tointegerx(L,i,is))
#define lua_tounsigned(L,i) lua_tounsignedx(L,(i),NULL)
#endif
#define lua_newuserdata(L,s) lua_newuserdatauv(L,s,1)
#define lua_getuservalue(L,idx) lua_getiuservalue(L,idx,1)
#define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1)
#define LUA_NUMTAGS LUA_NUMTYPES
/* }============================================================== */
/*
** {======================================================================
** Debug API
** =======================================================================
*/
/*
** Event codes
*/
#define LUA_HOOKCALL 0
#define LUA_HOOKRET 1
#define LUA_HOOKLINE 2
#define LUA_HOOKCOUNT 3
#define LUA_HOOKTAILCALL 4
/*
** Event masks
*/
#define LUA_MASKCALL (1 << LUA_HOOKCALL)
#define LUA_MASKRET (1 << LUA_HOOKRET)
#define LUA_MASKLINE (1 << LUA_HOOKLINE)
#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT)
typedef struct lua_Debug lua_Debug; /* activation record */
/* Functions to be called by the debugger in specific events */
typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
LUA_API int (lua_getstack) (lua_State *L, int level, lua_Debug *ar);
LUA_API int (lua_getinfo) (lua_State *L, const char *what, lua_Debug *ar);
LUA_API const char *(lua_getlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_setlocal) (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *(lua_getupvalue) (lua_State *L, int funcindex, int n);
LUA_API const char *(lua_setupvalue) (lua_State *L, int funcindex, int n);
LUA_API void *(lua_upvalueid) (lua_State *L, int fidx, int n);
LUA_API void (lua_upvaluejoin) (lua_State *L, int fidx1, int n1,
int fidx2, int n2);
LUA_API void (lua_sethook) (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook (lua_gethook) (lua_State *L);
LUA_API int (lua_gethookmask) (lua_State *L);
LUA_API int (lua_gethookcount) (lua_State *L);
LUA_API int (lua_setcstacklimit) (lua_State *L, unsigned int limit);
struct lua_Debug {
int event;
const char *name; /* (n) */
const char *namewhat; /* (n) 'global', 'local', 'field', 'method' */
const char *what; /* (S) 'Lua', 'C', 'main', 'tail' */
const char *source; /* (S) */
size_t srclen; /* (S) */
int currentline; /* (l) */
int linedefined; /* (S) */
int lastlinedefined; /* (S) */
unsigned char nups; /* (u) number of upvalues */
unsigned char nparams;/* (u) number of parameters */
char isvararg; /* (u) */
char istailcall; /* (t) */
unsigned short ftransfer; /* (r) index of first value transferred */
unsigned short ntransfer; /* (r) number of transferred values */
char short_src[LUA_IDSIZE]; /* (S) */
/* private part */
struct CallInfo *i_ci; /* active function */
};
/* }====================================================================== */
/******************************************************************************
* Copyright (C) 1994-2020 Lua.org, PUC-Rio.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#endif

9
vendor/lua/5.4/include/lua.hpp vendored Normal file
View File

@@ -0,0 +1,9 @@
// lua.hpp
// Lua header files for C++
// <<extern "C">> not supplied automatically because Lua also compiles as C++
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

763
vendor/lua/5.4/include/luaconf.h vendored Normal file
View File

@@ -0,0 +1,763 @@
/*
** $Id: luaconf.h $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
#ifndef luaconf_h
#define luaconf_h
#include <limits.h>
#include <stddef.h>
/*
** ===================================================================
** General Configuration File for Lua
**
** Some definitions here can be changed externally, through the
** compiler (e.g., with '-D' options). Those are protected by
** '#if !defined' guards. However, several other definitions should
** be changed directly here, either because they affect the Lua
** ABI (by making the changes here, you ensure that all software
** connected to Lua, such as C libraries, will be compiled with the
** same configuration); or because they are seldom changed.
**
** Search for "@@" to find all configurable definitions.
** ===================================================================
*/
/*
** {====================================================================
** System Configuration: macros to adapt (if needed) Lua to some
** particular platform, for instance restricting it to C89.
** =====================================================================
*/
/*
@@ LUA_USE_C89 controls the use of non-ISO-C89 features.
** Define it if you want Lua to avoid the use of a few C99 features
** or Windows-specific features on Windows.
*/
/* #define LUA_USE_C89 */
/*
** By default, Lua on Windows use (some) specific Windows features
*/
#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)
#define LUA_USE_WINDOWS /* enable goodies for regular Windows */
#endif
#if defined(LUA_USE_WINDOWS)
#define LUA_DL_DLL /* enable support for DLL */
#define LUA_USE_C89 /* broadly, Windows is C89 */
#endif
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
#endif
#if defined(LUA_USE_MACOSX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* MacOS does not need -ldl */
#endif
/*
@@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits.
*/
#define LUAI_IS32INT ((UINT_MAX >> 30) >= 3)
/* }================================================================== */
/*
** {==================================================================
** Configuration for Number types.
** ===================================================================
*/
/*
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.
*/
/* #define LUA_32BITS */
/*
@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
** C89 ('long' and 'double'); Windows always has '__int64', so it does
** not need to use this case.
*/
#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
#define LUA_C89_NUMBERS
#endif
/*
@@ LUA_INT_TYPE defines the type for Lua integers.
@@ LUA_FLOAT_TYPE defines the type for Lua floats.
** Lua should work fine with any mix of these options supported
** by your C compiler. The usual configurations are 64-bit integers
** and 'double' (the default), 32-bit integers and 'float' (for
** restricted platforms), and 'long'/'double' (for C compilers not
** compliant with C99, which may not have support for 'long long').
*/
/* predefined options for LUA_INT_TYPE */
#define LUA_INT_INT 1
#define LUA_INT_LONG 2
#define LUA_INT_LONGLONG 3
/* predefined options for LUA_FLOAT_TYPE */
#define LUA_FLOAT_FLOAT 1
#define LUA_FLOAT_DOUBLE 2
#define LUA_FLOAT_LONGDOUBLE 3
#if defined(LUA_32BITS) /* { */
/*
** 32-bit integers and 'float'
*/
#if LUAI_IS32INT /* use 'int' if big enough */
#define LUA_INT_TYPE LUA_INT_INT
#else /* otherwise use 'long' */
#define LUA_INT_TYPE LUA_INT_LONG
#endif
#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
#elif defined(LUA_C89_NUMBERS) /* }{ */
/*
** largest types available for C89 ('long' and 'double')
*/
#define LUA_INT_TYPE LUA_INT_LONG
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
#endif /* } */
/*
** default configuration for 64-bit Lua ('long long' and 'double')
*/
#if !defined(LUA_INT_TYPE)
#define LUA_INT_TYPE LUA_INT_LONGLONG
#endif
#if !defined(LUA_FLOAT_TYPE)
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
#endif
/* }================================================================== */
/*
** {==================================================================
** Configuration for Paths.
** ===================================================================
*/
/*
** LUA_PATH_SEP is the character that separates templates in a path.
** LUA_PATH_MARK is the string that marks the substitution points in a
** template.
** LUA_EXEC_DIR in a Windows path is replaced by the executable's
** directory.
*/
#define LUA_PATH_SEP ";"
#define LUA_PATH_MARK "?"
#define LUA_EXEC_DIR "!"
/*
@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
** Lua libraries.
@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
** C libraries.
** CHANGE them if your machine has a non-conventional directory
** hierarchy or if you want to install your libraries in
** non-conventional directories.
*/
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
#if defined(_WIN32) /* { */
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
*/
#define LUA_LDIR "!\\lua\\"
#define LUA_CDIR "!\\"
#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"
#if !defined(LUA_PATH_DEFAULT)
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
".\\?.lua;" ".\\?\\init.lua"
#endif
#if !defined(LUA_CPATH_DEFAULT)
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.dll;" \
LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \
LUA_CDIR"loadall.dll;" ".\\?.dll;" \
LUA_CDIR"?54.dll;" ".\\?54.dll"
#endif
#else /* }{ */
#define LUA_ROOT "/usr/local/"
#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/"
#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/"
#if !defined(LUA_PATH_DEFAULT)
#define LUA_PATH_DEFAULT \
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \
"./?.lua;" "./?/init.lua"
#endif
#if !defined(LUA_CPATH_DEFAULT)
#define LUA_CPATH_DEFAULT \
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so;" \
LUA_CDIR"lib?54.so;" "./lib?54.so"
#endif
#endif /* } */
/*
@@ LUA_DIRSEP is the directory separator (for submodules).
** CHANGE it if your machine does not use "/" as the directory separator
** and is not Windows. (On Windows Lua automatically uses "\".)
*/
#if !defined(LUA_DIRSEP)
#if defined(_WIN32)
#define LUA_DIRSEP "\\"
#else
#define LUA_DIRSEP "/"
#endif
#endif
/* }================================================================== */
/*
** {==================================================================
** Marks for exported symbols in the C code
** ===================================================================
*/
/*
@@ LUA_API is a mark for all core API functions.
@@ LUALIB_API is a mark for all auxiliary library functions.
@@ LUAMOD_API is a mark for all standard library opening functions.
** CHANGE them if you need to define those functions in some special way.
** For instance, if you want to create one Windows DLL with the core and
** the libraries, you may want to use the following definition (define
** LUA_BUILD_AS_DLL to get it).
*/
#if defined(LUA_BUILD_AS_DLL) /* { */
#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
#define LUA_API __declspec(dllexport)
#else /* }{ */
#define LUA_API __declspec(dllimport)
#endif /* } */
#else /* }{ */
#define LUA_API extern
#endif /* } */
/*
** More often than not the libs go together with the core.
*/
#define LUALIB_API LUA_API
#define LUAMOD_API LUA_API
/*
@@ LUAI_FUNC is a mark for all extern functions that are not to be
** exported to outside modules.
@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables,
** none of which to be exported to outside modules (LUAI_DDEF for
** definitions and LUAI_DDEC for declarations).
** CHANGE them if you need to mark them in some special way. Elf/gcc
** (versions 3.2 and later) mark them as "hidden" to optimize access
** when Lua is compiled as a shared library. Not all elf targets support
** this attribute. Unfortunately, gcc does not offer a way to check
** whether the target offers that support, and those without support
** give a warning about it. To avoid these warnings, change to the
** default definition.
*/
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
defined(__ELF__) /* { */
#define LUAI_FUNC __attribute__((visibility("internal"))) extern
#else /* }{ */
#define LUAI_FUNC extern
#endif /* } */
#define LUAI_DDEC(dec) LUAI_FUNC dec
#define LUAI_DDEF /* empty */
/* }================================================================== */
/*
** {==================================================================
** Compatibility with previous versions
** ===================================================================
*/
/*
@@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3.
** You can define it to get all options, or change specific options
** to fit your specific needs.
*/
#if defined(LUA_COMPAT_5_3) /* { */
/*
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
** functions in the mathematical library.
** (These functions were already officially removed in 5.3;
** nevertheless they are still available here.)
*/
#define LUA_COMPAT_MATHLIB
/*
@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
** luaL_checkint, luaL_checklong, etc.)
** (These macros were also officially removed in 5.3, but they are still
** available here.)
*/
#define LUA_COMPAT_APIINTCASTS
/*
@@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod
** using '__lt'.
*/
#define LUA_COMPAT_LT_LE
/*
@@ The following macros supply trivial compatibility for some
** changes in the API. The macros themselves document how to
** change your code to avoid using them.
** (Once more, these macros were officially removed in 5.3, but they are
** still available here.)
*/
#define lua_strlen(L,i) lua_rawlen(L, (i))
#define lua_objlen(L,i) lua_rawlen(L, (i))
#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
#endif /* } */
/* }================================================================== */
/*
** {==================================================================
** Configuration for Numbers.
** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
** satisfy your needs.
** ===================================================================
*/
/*
@@ LUA_NUMBER is the floating-point type used by Lua.
@@ LUAI_UACNUMBER is the result of a 'default argument promotion'
@@ over a floating number.
@@ l_floatatt(x) corrects float attribute 'x' to the proper float type
** by prefixing it with one of FLT/DBL/LDBL.
@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
@@ LUA_NUMBER_FMT is the format for writing floats.
@@ lua_number2str converts a float to a string.
@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
@@ l_floor takes the floor of a float.
@@ lua_str2number converts a decimal numeral to a number.
*/
/* The following definitions are good for most cases here */
#define l_floor(x) (l_mathop(floor)(x))
#define lua_number2str(s,sz,n) \
l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))
/*
@@ lua_numbertointeger converts a float number with an integral value
** to an integer, or returns 0 if float is not within the range of
** a lua_Integer. (The range comparisons are tricky because of
** rounding. The tests here assume a two-complement representation,
** where MININTEGER always has an exact representation as a float;
** MAXINTEGER may not have one, and therefore its conversion to float
** may have an ill-defined value.)
*/
#define lua_numbertointeger(n,p) \
((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
(n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
(*(p) = (LUA_INTEGER)(n), 1))
/* now the variable definitions */
#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */
#define LUA_NUMBER float
#define l_floatatt(n) (FLT_##n)
#define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN ""
#define LUA_NUMBER_FMT "%.7g"
#define l_mathop(op) op##f
#define lua_str2number(s,p) strtof((s), (p))
#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */
#define LUA_NUMBER long double
#define l_floatatt(n) (LDBL_##n)
#define LUAI_UACNUMBER long double
#define LUA_NUMBER_FRMLEN "L"
#define LUA_NUMBER_FMT "%.19Lg"
#define l_mathop(op) op##l
#define lua_str2number(s,p) strtold((s), (p))
#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */
#define LUA_NUMBER double
#define l_floatatt(n) (DBL_##n)
#define LUAI_UACNUMBER double
#define LUA_NUMBER_FRMLEN ""
#define LUA_NUMBER_FMT "%.14g"
#define l_mathop(op) op
#define lua_str2number(s,p) strtod((s), (p))
#else /* }{ */
#error "numeric float type not defined"
#endif /* } */
/*
@@ LUA_INTEGER is the integer type used by Lua.
**
@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
**
@@ LUAI_UACINT is the result of a 'default argument promotion'
@@ over a LUA_INTEGER.
@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
@@ LUA_INTEGER_FMT is the format for writing integers.
@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.
@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.
@@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED.
@@ LUA_UNSIGNEDBITS is the number of bits in a LUA_UNSIGNED.
@@ lua_integer2str converts an integer to a string.
*/
/* The following definitions are good for most cases here */
#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
#define LUAI_UACINT LUA_INTEGER
#define lua_integer2str(s,sz,n) \
l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))
/*
** use LUAI_UACINT here to avoid problems with promotions (which
** can turn a comparison between unsigneds into a signed comparison)
*/
#define LUA_UNSIGNED unsigned LUAI_UACINT
#define LUA_UNSIGNEDBITS (sizeof(LUA_UNSIGNED) * CHAR_BIT)
/* now the variable definitions */
#if LUA_INT_TYPE == LUA_INT_INT /* { int */
#define LUA_INTEGER int
#define LUA_INTEGER_FRMLEN ""
#define LUA_MAXINTEGER INT_MAX
#define LUA_MININTEGER INT_MIN
#define LUA_MAXUNSIGNED UINT_MAX
#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */
#define LUA_INTEGER long
#define LUA_INTEGER_FRMLEN "l"
#define LUA_MAXINTEGER LONG_MAX
#define LUA_MININTEGER LONG_MIN
#define LUA_MAXUNSIGNED ULONG_MAX
#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */
/* use presence of macro LLONG_MAX as proxy for C99 compliance */
#if defined(LLONG_MAX) /* { */
/* use ISO C99 stuff */
#define LUA_INTEGER long long
#define LUA_INTEGER_FRMLEN "ll"
#define LUA_MAXINTEGER LLONG_MAX
#define LUA_MININTEGER LLONG_MIN
#define LUA_MAXUNSIGNED ULLONG_MAX
#elif defined(LUA_USE_WINDOWS) /* }{ */
/* in Windows, can use specific Windows types */
#define LUA_INTEGER __int64
#define LUA_INTEGER_FRMLEN "I64"
#define LUA_MAXINTEGER _I64_MAX
#define LUA_MININTEGER _I64_MIN
#define LUA_MAXUNSIGNED _UI64_MAX
#else /* }{ */
#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \
or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
#endif /* } */
#else /* }{ */
#error "numeric integer type not defined"
#endif /* } */
/* }================================================================== */
/*
** {==================================================================
** Dependencies with C99 and other C details
** ===================================================================
*/
/*
@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.
** (All uses in Lua have only one format item.)
*/
#if !defined(LUA_USE_C89)
#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i)
#else
#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i))
#endif
/*
@@ lua_strx2number converts a hexadecimal numeral to a number.
** In C99, 'strtod' does that conversion. Otherwise, you can
** leave 'lua_strx2number' undefined and Lua will provide its own
** implementation.
*/
#if !defined(LUA_USE_C89)
#define lua_strx2number(s,p) lua_str2number(s,p)
#endif
/*
@@ lua_pointer2str converts a pointer to a readable string in a
** non-specified way.
*/
#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p)
/*
@@ lua_number2strx converts a float to a hexadecimal numeral.
** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
** provide its own implementation.
*/
#if !defined(LUA_USE_C89)
#define lua_number2strx(L,b,sz,f,n) \
((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))
#endif
/*
** 'strtof' and 'opf' variants for math functions are not valid in
** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the
** availability of these variants. ('math.h' is already included in
** all files that use these macros.)
*/
#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))
#undef l_mathop /* variants not available */
#undef lua_str2number
#define l_mathop(op) (lua_Number)op /* no variant */
#define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))
#endif
/*
@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation
** functions. It must be a numerical type; Lua will use 'intptr_t' if
** available, otherwise it will use 'ptrdiff_t' (the nearest thing to
** 'intptr_t' in C89)
*/
#define LUA_KCONTEXT ptrdiff_t
#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
__STDC_VERSION__ >= 199901L
#include <stdint.h>
#if defined(INTPTR_MAX) /* even in C99 this type is optional */
#undef LUA_KCONTEXT
#define LUA_KCONTEXT intptr_t
#endif
#endif
/*
@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
** Change that if you do not want to use C locales. (Code using this
** macro must include the header 'locale.h'.)
*/
#if !defined(lua_getlocaledecpoint)
#define lua_getlocaledecpoint() (localeconv()->decimal_point[0])
#endif
/* }================================================================== */
/*
** {==================================================================
** Language Variations
** =====================================================================
*/
/*
@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some
** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from
** numbers to strings. Define LUA_NOCVTS2N to turn off automatic
** coercion from strings to numbers.
*/
/* #define LUA_NOCVTN2S */
/* #define LUA_NOCVTS2N */
/*
@@ LUA_USE_APICHECK turns on several consistency checks on the C API.
** Define it as a help when debugging C code.
*/
#if defined(LUA_USE_APICHECK)
#include <assert.h>
#define luai_apicheck(l,e) assert(e)
#endif
/* }================================================================== */
/*
** {==================================================================
** Macros that affect the API and must be stable (that is, must be the
** same when you compile Lua and when you compile code that links to
** Lua).
** =====================================================================
*/
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
** (It must fit into max(size_t)/32.)
*/
#if LUAI_IS32INT
#define LUAI_MAXSTACK 1000000
#else
#define LUAI_MAXSTACK 15000
#endif
/*
@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
** a Lua state with very fast access.
** CHANGE it if you need a different size.
*/
#define LUA_EXTRASPACE (sizeof(void *))
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@@ of a function in debug information.
** CHANGE it if you want a different size.
*/
#define LUA_IDSIZE 60
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
*/
#define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number)))
/*
@@ LUAI_MAXALIGN defines fields that, when used in a union, ensure
** maximum alignment for the other items in that union.
*/
#define LUAI_MAXALIGN lua_Number n; double u; void *s; lua_Integer i; long l
/* }================================================================== */
/* =================================================================== */
/*
** Local configuration. You can use this space to add your redefinitions
** without modifying the main part of the file.
*/
#endif

58
vendor/lua/5.4/include/lualib.h vendored Normal file
View File

@@ -0,0 +1,58 @@
/*
** $Id: lualib.h $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
#ifndef lualib_h
#define lualib_h
#include "lua.h"
/* version suffix for environment variable names */
#define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR
LUAMOD_API int (luaopen_base) (lua_State *L);
#define LUA_COLIBNAME "coroutine"
LUAMOD_API int (luaopen_coroutine) (lua_State *L);
#define LUA_TABLIBNAME "table"
LUAMOD_API int (luaopen_table) (lua_State *L);
#define LUA_IOLIBNAME "io"
LUAMOD_API int (luaopen_io) (lua_State *L);
#define LUA_OSLIBNAME "os"
LUAMOD_API int (luaopen_os) (lua_State *L);
#define LUA_STRLIBNAME "string"
LUAMOD_API int (luaopen_string) (lua_State *L);
#define LUA_UTF8LIBNAME "utf8"
LUAMOD_API int (luaopen_utf8) (lua_State *L);
#define LUA_MATHLIBNAME "math"
LUAMOD_API int (luaopen_math) (lua_State *L);
#define LUA_DBLIBNAME "debug"
LUAMOD_API int (luaopen_debug) (lua_State *L);
#define LUA_LOADLIBNAME "package"
LUAMOD_API int (luaopen_package) (lua_State *L);
/* open all previous libraries */
LUALIB_API void (luaL_openlibs) (lua_State *L);
#if !defined(lua_assert)
#define lua_assert(x) ((void)0)
#endif
#endif

BIN
vendor/lua/5.4/linux/liblua54.a vendored Normal file

Binary file not shown.

BIN
vendor/lua/5.4/linux/liblua54.so vendored Normal file

Binary file not shown.

826
vendor/lua/5.4/lua.odin vendored Normal file
View File

@@ -0,0 +1,826 @@
package lua_5_4
import "core:intrinsics"
import "core:builtin"
import c "core:c/libc"
#assert(size_of(c.int) == size_of(b32))
when ODIN_OS == .Windows {
foreign import lib "windows/lua54dll.lib"
} else when ODIN_OS == .Linux {
foreign import lib "linux/liblua54.a"
} else {
foreign import lib "system:liblua54.a"
}
VERSION_MAJOR :: "5"
VERSION_MINOR :: "4"
VERSION_RELEASE :: "2"
VERSION_NUM :: 504
VERSION_RELEASE_NUM :: VERSION_NUM * 100 + 0
VERSION :: "Lua " + VERSION_MAJOR + "." + VERSION_MINOR
RELEASE :: VERSION + "." + VERSION_RELEASE
COPYRIGHT :: RELEASE + " Copyright (C) 1994-2020 Lua.org, PUC-Rio"
AUTHORS :: "R. Ierusalimschy, L. H. de Figueiredo, W. Celes"
/* mark for precompiled code ('<esc>Lua') */
SIGNATURE :: "\x1bLua"
/* option for multiple returns in 'lua_pcall' and 'lua_call' */
MULTRET :: -1
REGISTRYINDEX :: -MAXSTACK - 1000
/*
@@ LUAI_MAXSTACK limits the size of the Lua stack.
** CHANGE it if you need a different limit. This limit is arbitrary;
** its only purpose is to stop Lua from consuming unlimited stack
** space (and to reserve some numbers for pseudo-indices).
** (It must fit into max(size_t)/32.)
*/
MAXSTACK :: 1000000 when size_of(rawptr) == 4 else 15000
/*
@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
** a Lua state with very fast access.
** CHANGE it if you need a different size.
*/
EXTRASPACE :: size_of(rawptr)
/*
@@ LUA_IDSIZE gives the maximum size for the description of the source
@@ of a function in debug information.
** CHANGE it if you want a different size.
*/
IDSIZE :: 60
/*
@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
*/
L_BUFFERSIZE :: c.int(16 * size_of(rawptr) * size_of(Number))
MAXALIGNVAL :: max(align_of(Number), align_of(f64), align_of(rawptr), align_of(Integer), align_of(c.long))
Status :: enum c.int {
OK = 0,
YIELD = 1,
ERRRUN = 2,
ERRSYNTAX = 3,
ERRMEM = 4,
ERRERR = 5,
ERRFILE = 6,
}
/* thread status */
OK :: Status.OK
YIELD :: Status.YIELD
ERRRUN :: Status.ERRRUN
ERRSYNTAX :: Status.ERRSYNTAX
ERRMEM :: Status.ERRMEM
ERRERR :: Status.ERRERR
ERRFILE :: Status.ERRFILE
/*
** basic types
*/
Type :: enum c.int {
NONE = -1,
NIL = 0,
BOOLEAN = 1,
LIGHTUSERDATA = 2,
NUMBER = 3,
STRING = 4,
TABLE = 5,
FUNCTION = 6,
USERDATA = 7,
THREAD = 8,
}
TNONE :: Type.NONE
TNIL :: Type.NIL
TBOOLEAN :: Type.BOOLEAN
TLIGHTUSERDATA :: Type.LIGHTUSERDATA
TNUMBER :: Type.NUMBER
TSTRING :: Type.STRING
TTABLE :: Type.TABLE
TFUNCTION :: Type.FUNCTION
TUSERDATA :: Type.USERDATA
TTHREAD :: Type.THREAD
NUMTYPES :: 9
ArithOp :: enum c.int {
ADD = 0, /* ORDER TM, ORDER OP */
SUB = 1,
MUL = 2,
MOD = 3,
POW = 4,
DIV = 5,
IDIV = 6,
BAND = 7,
BOR = 8,
BXOR = 9,
SHL = 10,
SHR = 11,
UNM = 12,
BNOT = 13,
}
CompareOp :: enum c.int {
EQ = 0,
LT = 1,
LE = 2,
}
OPADD :: ArithOp.ADD
OPSUB :: ArithOp.SUB
OPMUL :: ArithOp.MUL
OPMOD :: ArithOp.MOD
OPPOW :: ArithOp.POW
OPDIV :: ArithOp.DIV
OPIDIV :: ArithOp.IDIV
OPBAND :: ArithOp.BAND
OPBOR :: ArithOp.BOR
OPBXOR :: ArithOp.BXOR
OPSHL :: ArithOp.SHL
OPSHR :: ArithOp.SHR
OPUNM :: ArithOp.UNM
OPBNOT :: ArithOp.BNOT
OPEQ :: CompareOp.EQ
OPLT :: CompareOp.LT
OPLE :: CompareOp.LE
/* minimum Lua stack available to a C function */
MINSTACK :: 20
/* predefined values in the registry */
RIDX_MAINTHREAD :: 1
RIDX_GLOBALS :: 2
RIDX_LAST :: RIDX_GLOBALS
/* type of numbers in Lua */
Number :: distinct (f32 when size_of(uintptr) == 4 else f64)
/* type for integer functions */
Integer :: distinct (i32 when size_of(uintptr) == 4 else i64)
/* unsigned integer type */
Unsigned :: distinct (u32 when size_of(uintptr) == 4 else u64)
/* type for continuation-function contexts */
KContext :: distinct int
/*
** Type for C functions registered with Lua
*/
CFunction :: #type proc "c" (L: ^State) -> c.int
/*
** Type for continuation functions
*/
KFunction :: #type proc "c" (L: ^State, status: c.int, ctx: KContext) -> c.int
/*
** Type for functions that read/write blocks when loading/dumping Lua chunks
*/
Reader :: #type proc "c" (L: ^State, ud: rawptr, sz: ^c.size_t) -> cstring
Writer :: #type proc "c" (L: ^State, p: rawptr, sz: ^c.size_t, ud: rawptr) -> c.int
/*
** Type for memory-allocation functions
*/
Alloc :: #type proc "c" (ud: rawptr, ptr: rawptr, osize, nsize: c.size_t) -> rawptr
/*
** Type for warning functions
*/
WarnFunction :: #type proc "c" (ud: rawptr, msg: rawptr, tocont: c.int)
GCWhat :: enum c.int {
STOP = 0,
RESTART = 1,
COLLECT = 2,
COUNT = 3,
COUNTB = 4,
STEP = 5,
SETPAUSE = 6,
SETSTEPMUL = 7,
ISRUNNING = 9,
GEN = 10,
INC = 11,
}
GCSTOP :: GCWhat.STOP
GCRESTART :: GCWhat.RESTART
GCCOLLECT :: GCWhat.COLLECT
GCCOUNT :: GCWhat.COUNT
GCCOUNTB :: GCWhat.COUNTB
GCSTEP :: GCWhat.STEP
GCSETPAUSE :: GCWhat.SETPAUSE
GCSETSTEPMUL :: GCWhat.SETSTEPMUL
GCISRUNNING :: GCWhat.ISRUNNING
GCGEN :: GCWhat.GEN
GCINC :: GCWhat.INC
/*
** Event codes
*/
HookEvent :: enum c.int {
CALL = 0,
RET = 1,
LINE = 2,
COUNT = 3,
TAILCALL = 4,
}
HOOKCALL :: HookEvent.CALL
HOOKRET :: HookEvent.RET
HOOKLINE :: HookEvent.LINE
HOOKCOUNT :: HookEvent.COUNT
HOOKTAILCALL :: HookEvent.TAILCALL
/*
** Event masks
*/
HookMask :: distinct bit_set[HookEvent; c.int]
MASKCALL :: HookMask{.CALL}
MASKRET :: HookMask{.RET}
MASKLINE :: HookMask{.LINE}
MASKCOUNT :: HookMask{.COUNT}
/* activation record */
Debug :: struct {
event: HookEvent,
name: cstring, /* (n) */
namewhat: cstring, /* (n) 'global', 'local', 'field', 'method' */
what: cstring, /* (S) 'Lua', 'C', 'main', 'tail' */
source: cstring, /* (S) */
srclen: c.size_t, /* (S) */
currentline: c.int, /* (l) */
linedefined: c.int, /* (S) */
lastlinedefined: c.int, /* (S) */
nups: u8, /* (u) number of upvalues */
nparams: u8, /* (u) number of parameters */
isvararg: bool, /* (u) */
istailcall: bool, /* (t) */
ftransfer: u16, /* (r) index of first value transferred */
ntransfer: u16, /* (r) number of transferred values */
short_src: [IDSIZE]u8 `fmt:"s"`, /* (S) */
/* private part */
i_ci: rawptr, /* active function */
}
/* Functions to be called by the debugger in specific events */
Hook :: #type proc "c" (L: ^State, ar: ^Debug)
State :: struct {} // opaque data type
@(link_prefix="lua_")
@(default_calling_convention="c")
foreign lib {
/*
** RCS ident string
*/
ident: [^]u8 // TODO(bill): is this correct?
/*
** state manipulation
*/
newstate :: proc(f: Alloc, ud: rawptr) -> ^State ---
close :: proc(L: ^State) ---
newthread :: proc(L: ^State) -> ^State ---
resetthread :: proc(L: ^State) -> Status ---
atpanic :: proc(L: ^State, panicf: CFunction) -> CFunction ---
version :: proc(L: ^State) -> Number ---
/*
** basic stack manipulation
*/
absindex :: proc (L: ^State, idx: c.int) -> c.int ---
gettop :: proc (L: ^State) -> c.int ---
settop :: proc (L: ^State, idx: c.int) ---
pushvalue :: proc (L: ^State, idx: c.int) ---
rotate :: proc (L: ^State, idx: c.int, n: c.int) ---
copy :: proc (L: ^State, fromidx, toidx: c.int) ---
checkstack :: proc (L: ^State, n: c.int) -> c.int ---
xmove :: proc(from, to: ^State, n: c.int) ---
/*
** access functions (stack -> C)
*/
isnumber :: proc(L: ^State, idx: c.int) -> b32 ---
isstring :: proc(L: ^State, idx: c.int) -> b32 ---
iscfunction :: proc(L: ^State, idx: c.int) -> b32 ---
isinteger :: proc(L: ^State, idx: c.int) -> b32 ---
isuserdata :: proc(L: ^State, idx: c.int) -> b32 ---
type :: proc(L: ^State, idx: c.int) -> Type ---
typename :: proc(L: ^State, tp: Type) -> cstring ---
@(link_name="lua_tonumberx")
tonumber :: proc(L: ^State, idx: c.int, isnum: ^b32 = nil) -> Number ---
@(link_name="lua_tointegerx")
tointeger :: proc(L: ^State, idx: c.int, isnum: ^b32 = nil) -> Integer ---
toboolean :: proc(L: ^State, idx: c.int) -> b32 ---
tolstring :: proc(L: ^State, idx: c.int, len: ^c.size_t) -> cstring ---
rawlen :: proc(L: ^State, idx: c.int) -> Unsigned ---
tocfunction :: proc(L: ^State, idx: c.int) -> CFunction ---
touserdata :: proc(L: ^State, idx: c.int) -> rawptr ---
tothread :: proc(L: ^State, idx: c.int) -> ^State ---
topointer :: proc(L: ^State, idx: c.int) -> rawptr ---
/*
** Comparison and arithmetic functions
*/
arith :: proc(L: ^State, op: ArithOp) ---
rawequal :: proc(L: ^State, idx1, idx2: c.int) -> b32 ---
compare :: proc(L: ^State, idx1, idx2: c.int, op: CompareOp) -> b32 ---
/*
** push functions (C -> stack)
*/
pushnil :: proc(L: ^State) ---
pushnumber :: proc(L: ^State, n: Number) ---
pushinteger :: proc(L: ^State, n: Integer) ---
pushlstring :: proc(L: ^State, s: cstring, len: c.size_t) -> cstring ---
pushstring :: proc(L: ^State, s: cstring) -> cstring ---
pushvfstring :: proc(L: ^State, fmt: cstring, argp: c.va_list) -> cstring ---
pushfstring :: proc(L: ^State, fmt: cstring, #c_vararg args: ..any) -> cstring ---
pushcclosure :: proc(L: ^State, fn: CFunction, n: c.int) ---
pushboolean :: proc(L: ^State, b: b32) ---
pushlightuserdata :: proc(L: ^State, p: rawptr) ---
pushthread :: proc(L: ^State) -> Status ---
/*
** get functions (Lua -> stack)
*/
getglobal :: proc(L: ^State, name: cstring) -> c.int ---
gettable :: proc(L: ^State, idx: c.int) -> c.int ---
getfield :: proc(L: ^State, idx: c.int, k: cstring) -> c.int ---
geti :: proc(L: ^State, idx: c.int, n: Integer) -> c.int ---
rawget :: proc(L: ^State, idx: c.int) -> c.int ---
rawgeti :: proc(L: ^State, idx: c.int, n: Integer) -> c.int ---
rawgetp :: proc(L: ^State, idx: c.int, p: rawptr) -> c.int ---
createtable :: proc(L: ^State, narr, nrec: c.int) ---
newuserdatauv :: proc(L: ^State, sz: c.size_t, nuvalue: c.int) -> rawptr ---
getmetatable :: proc(L: ^State, objindex: c.int) -> c.int ---
getiuservalue :: proc(L: ^State, idx: c.int, n: c.int) -> c.int ---
/*
** set functions (stack -> Lua)
*/
setglobal :: proc(L: ^State, name: cstring) ---
settable :: proc(L: ^State, idx: c.int) ---
setfield :: proc(L: ^State, idx: c.int, k: cstring) ---
seti :: proc(L: ^State, idx: c.int, n: Integer) ---
rawset :: proc(L: ^State, idx: c.int) ---
rawseti :: proc(L: ^State, idx: c.int, n: Integer) ---
rawsetp :: proc(L: ^State, idx: c.int, p: rawptr) ---
setmetatable :: proc(L: ^State, objindex: c.int) -> c.int ---
setiuservalue :: proc(L: ^State, idx: c.int, n: c.int) -> c.int ---
/*
** 'load' and 'call' functions (load and run Lua code)
*/
@(link_name="lua_callk")
call :: proc(L: ^State, nargs, nresults: c.int,
ctx: KContext = 0, k: KFunction = nil) ---
@(link_name="lua_pcallk")
pcall :: proc(L: ^State, nargs, nresults: c.int, errfunc: c.int,
ctx: KContext = 0, k: KFunction = nil) -> c.int ---
load :: proc(L: ^State, reader: Reader, dt: rawptr,
chunkname, mode: cstring) -> Status ---
dump :: proc(L: ^State, writer: Writer, data: rawptr, strip: b32) -> Status ---
/*
** coroutine functions
*/
@(link_name="lua_yieldk")
yield :: proc(L: ^State, nresults: c.int, ctx: KContext = 0, k: KFunction = nil) -> Status ---
resume :: proc(L: ^State, from: ^State, narg: c.int, nres: ^c.int) -> Status ---
status :: proc(L: ^State) -> Status ---
isyieldable :: proc(L: ^State) -> b32 ---
/*
** Warning-related functions
*/
setwarnf :: proc(L: ^State, f: WarnFunction, ud: rawptr) ---
warning :: proc(L: ^State, msg: string, tocont: b32) ---
/*
** garbage-collection function and options
*/
gc :: proc(L: ^State, what: GCWhat, #c_vararg args: ..any) -> c.int ---
/*
** miscellaneous functions
*/
error :: proc(L: ^State) -> Status ---
next :: proc(L: ^State, idx: c.int) -> c.int ---
concat :: proc(L: ^State, n: c.int) ---
len :: proc(L: ^State, idx: c.int) ---
stringtonumber :: proc(L: ^State, s: cstring) -> c.size_t ---
getallocf :: proc(L: State, ud: ^rawptr) -> Alloc ---
setallocf :: proc(L: ^State, f: Alloc, ud: rawptr) ---
toclose :: proc(L: ^State, idx: c.int) ---
/*
** {======================================================================
** Debug API
** =======================================================================
*/
getstack :: proc(L: ^State, level: c.int, ar: ^Debug) -> c.int ---
getinfo :: proc(L: ^State, what: cstring, ar: ^Debug) -> c.int ---
getlocal :: proc(L: ^State, ar: ^Debug, n: c.int) -> cstring ---
setlocal :: proc(L: ^State, ar: ^Debug, n: c.int) -> cstring ---
getupvalue :: proc(L: ^State, funcindex: c.int, n: c.int) -> cstring ---
setupvalue :: proc(L: ^State, funcindex: c.int, n: c.int) -> cstring ---
upvalueid :: proc(L: ^State, fidx, n: c.int) -> rawptr ---
upvaluejoin :: proc(L: ^State, fidx1, n1, fidx2, n2: c.int) ---
sethook :: proc(L: ^State, func: Hook, mask: HookMask, count: c.int) ---
gethook :: proc(L: ^State) -> Hook ---
gethookmask :: proc(L: ^State) -> HookMask ---
gethookcount :: proc(L: ^State) -> c.int ---
setcstacklimit :: proc(L: ^State, limit: c.uint) -> c.int ---
/* }============================================================== */
}
/* version suffix for environment variable names */
VERSUFFIX :: "_" + VERSION_MAJOR + "_" + VERSION_MINOR
COLIBNAME :: "coroutine"
TABLIBNAME :: "table"
IOLIBNAME :: "io"
OSLIBNAME :: "os"
STRLIBNAME :: "string"
UTF8LIBNAME :: "utf8"
MATHLIBNAME :: "math"
DBLIBNAME :: "debug"
LOADLIBNAME :: "package"
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
open_base :: proc(L: ^State) -> c.int ---
open_coroutine :: proc(L: ^State) -> c.int ---
open_table :: proc(L: ^State) -> c.int ---
open_io :: proc(L: ^State) -> c.int ---
open_os :: proc(L: ^State) -> c.int ---
open_string :: proc(L: ^State) -> c.int ---
open_utf8 :: proc(L: ^State) -> c.int ---
open_math :: proc(L: ^State) -> c.int ---
open_debug :: proc(L: ^State) -> c.int ---
open_package :: proc(L: ^State) -> c.int ---
/* open all previous libraries */
L_openlibs :: proc(L: ^State) ---
}
GNAME :: "_G"
/* key, in the registry, for table of loaded modules */
LOADED_TABLE :: "_LOADED"
/* key, in the registry, for table of preloaded loaders */
PRELOAD_TABLE :: "_PRELOAD"
L_Reg :: struct {
name: cstring,
func: CFunction,
}
L_NUMSIZES :: size_of(Integer)*16 + size_of(Number)
/* predefined references */
NOREF :: -2
REFNIL :: -1
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
@(link_name="luaL_checkversion_")
L_checkversion :: proc(L: ^State, ver: Number = VERSION_NUM, sz: c.size_t = L_NUMSIZES) ---
L_getmetafield :: proc(L: ^State, obj: c.int, e: cstring) -> c.int ---
L_callmeta :: proc(L: ^State, obj: c.int, e: cstring) -> c.int ---
@(link_name="luaL_tolstring")
L_tostring :: proc(L: ^State, idx: c.int, len: ^c.size_t = nil) -> cstring ---
L_argerror :: proc(L: ^State, arg: c.int, extramsg: cstring) -> c.int ---
L_typeerror :: proc(L: ^State, arg: c.int, tname: cstring) -> c.int ---
@(link_name="luaL_checklstring")
L_checkstring :: proc(L: ^State, arg: c.int, l: ^c.size_t = nil) -> cstring ---
@(link_name="luaL_optlstring")
L_optstring :: proc(L: ^State, arg: c.int, def: cstring, l: ^c.size_t = nil) -> cstring ---
L_checknumber :: proc(L: ^State, arg: c.int) -> Number ---
L_optnumber :: proc(L: ^State, arg: c.int, def: Number) -> Number ---
L_checkinteger :: proc(L: ^State, arg: c.int) -> Integer ---
L_optinteger :: proc(L: ^State, arg: c.int, def: Integer) -> Integer ---
L_checkstack :: proc(L: ^State, sz: c.int, msg: cstring) ---
L_checktype :: proc(L: ^State, arg: c.int, t: c.int) ---
L_checkany :: proc(L: ^State, arg: c.int) ---
L_newmetatable :: proc(L: ^State, tname: cstring) -> c.int ---
L_setmetatable :: proc(L: ^State, tname: cstring) ---
L_testudata :: proc(L: ^State, ud: c.int, tname: cstring) -> rawptr ---
L_checkudata :: proc(L: ^State, ud: c.int, tname: cstring) -> rawptr ---
L_where :: proc(L: ^State, lvl: c.int) ---
L_error :: proc(L: ^State, fmt: cstring, #c_vararg args: ..any) -> Status ---
L_checkoption :: proc(L: ^State, arg: c.int, def: cstring, lst: [^]cstring) -> c.int ---
L_fileresult :: proc(L: ^State, stat: c.int, fname: cstring) -> c.int ---
L_execresult :: proc(L: ^State, stat: c.int) -> c.int ---
L_ref :: proc(L: ^State, t: c.int) -> c.int ---
L_unref :: proc(L: ^State, t: c.int, ref: c.int) ---
@(link_name="luaL_loadfilex")
L_loadfile :: proc (L: ^State, filename: cstring, mode: cstring = nil) -> Status ---
@(link_name="luaL_loadbufferx")
L_loadbuffer :: proc(L: ^State, buff: [^]byte, sz: c.size_t, name: cstring, mode: cstring = nil) -> Status ---
L_loadstring :: proc(L: ^State, s: cstring) -> Status ---
L_newstate :: proc() -> ^State ---
L_len :: proc(L: ^State, idx: c.int) -> Integer ---
L_addgsub :: proc(b: ^L_Buffer, s, p, r: cstring) ---
L_gsub :: proc(L: ^State, s, p, r: cstring) -> cstring ---
L_setfuncs :: proc(L: ^State, l: [^]L_Reg, nup: c.int) ---
L_getsubtable :: proc(L: ^State, idx: c.int, fname: cstring) -> c.int ---
L_traceback :: proc(L: ^State, L1: ^State, msg: cstring, level: c.int) ---
L_requiref :: proc(L: ^State, modname: cstring, openf: CFunction, glb: c.int) ---
}
/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/
L_Buffer :: struct {
b: [^]byte, /* buffer address */
size: c.size_t, /* buffer size */
n: c.size_t, /* number of characters in buffer */
L: ^State,
init: struct #raw_union {
n: Number, u: f64, s: rawptr, i: Integer, l: c.long,
b: [L_BUFFERSIZE]byte, /* initial buffer */
},
}
L_bufflen :: #force_inline proc "c" (bf: ^L_Buffer) -> c.size_t {
return bf.n
}
L_buffaddr :: #force_inline proc "c" (bf: ^L_Buffer) -> [^]byte {
return bf.b
}
L_addchar :: #force_inline proc "c" (B: ^L_Buffer, c: byte) {
if B.n < B.size {
L_prepbuffsize(B, 1)
}
B.b[B.n] = c
B.n += 1
}
L_addsize :: #force_inline proc "c" (B: ^L_Buffer, s: c.size_t) -> c.size_t {
B.n += s
return B.n
}
L_buffsub :: #force_inline proc "c" (B: ^L_Buffer, s: c.size_t) -> c.size_t {
B.n -= s
return B.n
}
L_prepbuffer :: #force_inline proc "c" (B: ^L_Buffer) -> [^]byte {
return L_prepbuffsize(B, c.size_t(L_BUFFERSIZE))
}
@(link_prefix="lua")
@(default_calling_convention="c")
foreign lib {
L_buffinit :: proc(L: ^State, B: ^L_Buffer) ---
L_prepbuffsize :: proc(B: ^L_Buffer, sz: c.size_t) -> [^]byte ---
L_addlstring :: proc(B: ^L_Buffer, s: cstring, l: c.size_t) ---
L_addstring :: proc(B: ^L_Buffer, s: cstring) ---
L_addvalue :: proc(B: ^L_Buffer) ---
L_pushresult :: proc(B: ^L_Buffer) ---
L_pushresultsize :: proc(B: ^L_Buffer, sz: c.size_t) ---
L_buffinitsize :: proc(L: ^State, B: ^L_Buffer, sz: c.size_t) -> [^]byte ---
}
/* }====================================================== */
/*
** {==============================================================
** some useful macros
** ===============================================================
*/
getextraspace :: #force_inline proc "c" (L: ^State) -> rawptr {
return rawptr(([^]byte)(L)[-EXTRASPACE:])
}
pop :: #force_inline proc "c" (L: ^State, n: c.int) {
settop(L, -n-1)
}
newtable :: #force_inline proc "c" (L: ^State) {
createtable(L, 0, 0)
}
register :: #force_inline proc "c" (L: ^State, n: cstring, f: CFunction) {
pushcfunction(L, f)
setglobal(L, n)
}
pushcfunction :: #force_inline proc "c" (L: ^State, f: CFunction) {
pushcclosure(L, f, 0)
}
isfunction :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .FUNCTION }
istable :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .TABLE }
islightuserdata :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .LIGHTUSERDATA }
isnil :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .NIL }
isboolean :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .BOOLEAN }
isthread :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .THREAD }
isnone :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) == .NONE }
isnoneornil :: #force_inline proc "c" (L: ^State, n: c.int) -> bool { return type(L, n) <= .NIL }
pushliteral :: pushstring
pushglobaltable :: #force_inline proc "c" (L: ^State) {
rawgeti(L, REGISTRYINDEX, RIDX_GLOBALS)
}
tostring :: #force_inline proc "c" (L: ^State, i: c.int) -> cstring {
return tolstring(L, i, nil)
}
insert :: #force_inline proc "c" (L: ^State, idx: c.int) {
rotate(L, idx, 1)
}
remove :: #force_inline proc "c" (L: ^State, idx: c.int) {
rotate(L, idx, -1)
pop(L, 1)
}
replace :: #force_inline proc "c" (L: ^State, idx: c.int) {
copy(L, -1, idx)
pop(L, 1)
}
L_newlibtable :: #force_inline proc "c" (L: ^State, l: []L_Reg) {
createtable(L, 0, c.int(builtin.len(l) - 1))
}
L_newlib :: proc(L: ^State, l: []L_Reg) {
L_checkversion(L)
L_newlibtable(L, l)
L_setfuncs(L, raw_data(l), 0)
}
L_argcheck :: #force_inline proc "c" (L: ^State, cond: bool, arg: c.int, extramsg: cstring) {
if cond {
L_argerror(L, arg, extramsg)
}
}
L_argexpected :: #force_inline proc "c" (L: ^State, cond: bool, arg: c.int, tname: cstring) {
if cond {
L_typeerror(L, arg, tname)
}
}
L_typename :: #force_inline proc "c" (L: ^State, i: c.int) -> cstring {
return typename(L, type(L, i))
}
L_dofile :: #force_inline proc "c" (L: ^State, s: cstring) -> c.int {
err := L_loadfile(L, s)
return pcall(L, 0, MULTRET, 0) if err == nil else c.int(err)
}
L_dostring :: #force_inline proc "c" (L: ^State, s: cstring) -> c.int {
err := L_loadstring(L, s)
return pcall(L, 0, MULTRET, 0) if err == nil else c.int(err)
}
L_getmetatable :: #force_inline proc "c" (L: ^State, n: cstring) -> c.int {
return getfield(L, REGISTRYINDEX, n)
}
L_opt :: #force_inline proc "c" (L: ^State, f: $F, n: c.int, d: $T) -> T where intrinsics.type_is_proc(F) {
return d if isnoneornil(L, n) else f(L, n)
}
/* push the value used to represent failure/error */
pushfail :: pushnil
/* }============================================================== */
/*
** {==============================================================
** compatibility macros
** ===============================================================
*/
newuserdata :: #force_inline proc "c" (L: ^State, s: c.size_t) -> rawptr {
return newuserdatauv(L, s, 1)
}
getuservalue :: #force_inline proc "c" (L: ^State, idx: c.int) -> c.int {
return getiuservalue(L, idx, 1)
}
setuservalue :: #force_inline proc "c" (L: ^State, idx: c.int) -> c.int {
return setiuservalue(L, idx, 1)
}

BIN
vendor/lua/5.4/windows/lua54.dll vendored Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More