Module stubs stdlib

stubs
Version:
0.0.1
License:
MIT
Dependencies from vmod:
2
Imports:
2
Imported by:
0
Repository:
OS-specific
Show selected OS-specific symbols.
Backend-specific
Show selected Backend-specific symbols.

Dependencies defined in v.mod

  • srackham.pcre2
  • markdown

Imports

Imported by

This section is empty.

Overview

The stubs module contains files describing some features of the V language that are not explicitly described in the standard library.

For example, some compile-time functions or attributes.

This is not real code, it is only needed for Doki and IDE to be able to show documentation and jump to definitions.

Aliases

#type bool

type bool = bool

bool is the set of boolean values, true and false.

#type u8

type u8 = u8

u8 is the set of all unsigned 8-bit integers.

Range: 0 through 255.

#type u16

type u16 = u16

u16 is the set of all unsigned 16-bit integers.

Range: 0 through 65535.

#type u32

type u32 = u32

u32 is the set of all unsigned 32-bit integers.

Range: 0 through 4294967295.

#type u64

type u64 = u64

u64 is the set of all unsigned 64-bit integers.

Range: 0 through 18446744073709551615.

#type usize

type usize = u64

usize is platform-dependent unsigned integer type.

#type i8

type i8 = i8

i8 is the set of all signed 8-bit integers.

Range: -128 through 127.

#type i16

type i16 = i16

i16 is the set of all signed 16-bit integers.

Range: -32768 through 32767.

#type i32

type i32 = int

i32 is the set of all signed 32-bit integers.

Range: -2147483648 through 2147483647.

#type int

type int = int

int is the set of all signed 32-bit integers.

Range: -2147483648 through 2147483647.

#type i64

type i64 = i64

i64 is the set of all signed 64-bit integers.

Range: -9223372036854775808 through 9223372036854775807.

#type isize

type isize = i64

isize is platform-dependent integer type.

#type f32

type f32 = f32

f32 is the set of all IEEE-754 32-bit floating-point numbers.

#type f64

type f64 = f64

f64 is the set of all IEEE-754 64-bit floating-point numbers.

#type byte

type byte = u8

byte is an alias for u8 and is equivalent to u8 in all ways. It is used, by convention, to distinguish byte values from 8-bit unsigned integer values.

#type rune

type rune = int

rune is an alias for int and is equivalent to int in all ways. It is used, by convention, to distinguish character values from integer values.

#type char

type char = u8

char is an alias for u8 and is equivalent to u8 in all ways.

Mostly used for C interoperability.

#type voidptr

type voidptr = voidptr

voidptr is an untyped pointer.

Mostly used for C interoperability.

#type byteptr

type byteptr = byteptr

byteptr is a byte pointer.

Mostly used for C interoperability.

#type charptr

type charptr = charptr

charptr is a char pointer.

Mostly used for C interoperability.

Constants

#constant @FN

pub const @FN = ''

@FN replaced with the name of the current V function.

#constant @METHOD

pub const @METHOD = ''

@METHOD replaced with name of the current V method and receiver type: ReceiverType.MethodName.

#constant @MOD

pub const @MOD = ''

@MOD replaced with the name of the current V module.

#constant @STRUCT

pub const @STRUCT = ''

@STRUCT replaced with the name of the current V struct.

#constant @FILE

pub const @FILE = ''

@FILE replaced with the absolute path of the V source file.

#constant @LINE

pub const @LINE = ''

@LINE replaced with the V line number where it appears (as a string).

#constant @FILE_LINE

pub const @FILE_LINE = ''

@FILE_LINE replaced with @FILE:@LINE, but the file part is a relative path.

#constant @COLUMN

pub const @COLUMN = ''

@COLUMN replaced with the column where it appears (as a string).

#constant @VEXE

pub const @VEXE = ''

@VEXE replaced with the path to the V compiler.

#constant @VEXEROOT

pub const @VEXEROOT = ''

@VEXEROOT replaced with the folder, where the V executable is.

#constant @VHASH

pub const @VHASH = ''

@VHASH replaced with the shortened commit hash of the V compiler.

#constant @VMOD_FILE

pub const @VMOD_FILE = ''

@VMOD_FILE replaced with the contents of the nearest v.mod file.

#constant @VMODROOT

pub const @VMODROOT = ''

@VMODROOT replaced with the folder, where the nearest v.mod file is.

#constant windows

pub const windows = false

windows set to true if the current OS is Windows.

#constant linux

pub const linux = false

linux set to true if the current OS is Linux.

#constant macos

pub const macos = false

macos set to true if the current OS is macOS.

#constant mac

pub const mac = false

mac set to true if the current OS is macOS.

#constant darwin

pub const darwin = false

darwin set to true if the current OS is macOS.

#constant freebsd

pub const freebsd = false

freebsd set to true if the current OS is FreeBSD.

#constant openbsd

pub const openbsd = false

openbsd set to true if the current OS is OpenBSD.

#constant netbsd

pub const netbsd = false

netbsd set to true if the current OS is NetBSD.

#constant serenity

pub const serenity = false

serenity set to true if the current OS is Serenity.

#constant vinix

pub const vinix = false

vinix set to true if the current OS is Vinix.

#constant ios

pub const ios = false

ios set to true if the current OS is iOS.

#constant android

pub const android = false

android set to true if the current OS is Android.

#constant emscripten

pub const emscripten = false

emscripten set to true if the current OS is Emscripten.

#constant js_node

pub const js_node = false

js_node set to true if the current platform is Node.js.

#constant js_freestanding

pub const js_freestanding = false

js_freestanding set to true if the current platform is pure JavaScript.

#constant js_browser

pub const js_browser = false

js_browser set to true if the current platform is JavaScript in a browser.

#constant js

pub const js = false

js set to true if the current platform is JavaScript.

#constant mach

pub const mach = false

mach set to true if the current OS is Mach.

#constant dragonfly

pub const dragonfly = false

dragonfly set to true if the current OS is Dragonfly.

#constant gnu

pub const gnu = false

gnu set to true if the current OS is GNU.

#constant hpux

pub const hpux = false

hpux set to true if the current OS is HP-UX.

#constant haiku

pub const haiku = false

haiku set to true if the current OS is Haiku.

#constant qnx

pub const qnx = false

qnx set to true if the current OS is QNX.

#constant solaris

pub const solaris = false

solaris set to true if the current OS is Solaris.

#constant termux

pub const termux = false

termux set to true if the current OS is Termux.

#constant gcc

pub const gcc = false

gcc set to true if the current compiler is GCC.

#constant tiny

pub const tiny = false

tiny set to true if the current compiler is TinyCC.

#constant clang

pub const clang = false

clang set to true if the current compiler is Clang.

#constant mingw

pub const mingw = false

mingw set to true if the current compiler is MinGW.

#constant msvc

pub const msvc = false

msvc set to true if the current compiler is MSVC.

#constant cplusplus

pub const cplusplus = false

cpp set to true if the current compiler is C++.

#constant amd64

pub const amd64 = false

x86 set to true if the current platform is x86.

#constant arm64

pub const arm64 = false

arm set to true if the current platform is ARM.

#constant x64

pub const x64 = false

x64 set to true if the current platform is x64.

#constant x32

pub const x32 = false

x32 set to true if the current platform is x32.

#constant little_endian

pub const little_endian = false

little_endian set to true if the current platform is little endian.

#constant big_endian

pub const big_endian = false

big_endian set to true if the current platform is big endian.

#constant debug

pub const debug = false

debug set to true if the -g flag is passed to the compiler.

#constant prod

pub const prod = false

prod set to true if the -prod flag is passed to the compiler.

#constant test

pub const test = false

test set to true file run with v test.

#constant glibc

pub const glibc = false

glibc set to true if the -glibc flag is passed to the compiler.

#constant prealloc

pub const prealloc = false

prealloc set to true if the -prealloc flag is passed to the compiler.

#constant no_bounds_checking

pub const no_bounds_checking = false

no_bounds_checking set to true if the -no_bounds_checking flag is passed to the compiler.

#constant freestanding

pub const freestanding = false

freestanding set to true if the -freestanding flag is passed to the compiler.

#constant no_segfault_handler

pub const no_segfault_handler = false

no_segfault_handler set to true if the -no_segfault_handler flag is passed to the compiler.

#constant no_backtrace

pub const no_backtrace = false

no_backtrace set to true if the -no_backtrace flag is passed to the compiler.

#constant no_main

pub const no_main = false

no_main set to true if the -no_main flag is passed to the compiler.

#constant

pub const $int = TypeInfo{}

$int describes any integer type.

Example:

 $for f in Test.fields {
   $if f.typ is $int {
     println(f.name)
   }
 }

#constant

pub const $float = TypeInfo{}

$float describes any float type.

Example:

 $for f in Test.fields {
   $if f.typ is $float {
     println(f.name)
   }
 }

#constant

pub const $array = TypeInfo{}

$array describes any array type.

Example:

 $for f in Test.fields {
   $if f.typ is $array {
     println(f.name)
   }
 }

#constant

pub const $map = TypeInfo{}

$map describes any map type.

Example:

 $for f in Test.fields {
   $if f.typ is $map {
     println(f.name)
   }
 }

#constant

pub const $struct = TypeInfo{}

$struct describes any struct type.

Example:

 $for f in Test.fields {
   $if f.typ is $struct {
     println(f.name)
   }
 }

#constant

pub const $interface = TypeInfo{}

$interface describes any interface type.

Example:

 $for f in Test.fields {
   $if f.typ is $interface {
     println(f.name)
   }
 }

#constant

pub const $enum = TypeInfo{}

$enum describes any enum type.

Example:

 $for f in Test.fields {
   $if f.typ is $enum {
     println(f.name)
   }
 }

#constant

pub const $alias = TypeInfo{}

$alias describes any alias type.

Example:

 $for f in Test.fields {
   $if f.typ is $alias {
     println(f.name)
   }
 }

#constant

pub const $sumtype = TypeInfo{}

$sumtype describes any sumtype type.

Example:

 $for f in Test.fields {
   $if f.typ is $sumtype {
     println(f.name)
   }
 }

#constant

pub const $function = TypeInfo{}

$function describes any function type.

Example:

 $for f in Test.fields {
   $if f.typ is $function {
     println(f.name)
   }
 }

#constant

pub const $option = TypeInfo{}

$option describes any option type.

Example:

 $for f in Test.fields {
   $if f.typ is $option {
     println(f.name)
   }
 }

#constant err

pub const err = IError{}

err is a special variable that is set with an error and is used to handle errors in V.

It can be used inside two places:

  1. inside or block:
 fn foo() !int {
   return error("not implemented");
 }
 

foo() or {
   panic(err);
   //    ^^^ err is set with error("not implemented")
 }
  1. inside else block for if guard:
 fn foo() !int {
   return error("not implemented");
 }
 

if val := foo() {
   // val is set with int
 } else {
   panic(err);
   //    ^^^ err is set with error("not implemented")
 }

See Documentation for more details.

#constant

pub const $vweb = VWebTemplate{}

$vweb constant allows you to render HTML template in endpoint functions.

$vweb.html() in method like <folder>_<name>() vweb.Result render the <name>.html in folder ./templates/<folder>

$vweb.html() compiles an HTML template into V during compilation, and embeds the resulting code into the current function.

That means that the template automatically has access to that function's entire environment (like variables).

See vweb documentation for more information.

Example:

 ['/']
 pub fn (mut app App) page_home() vweb.Result {
   // will render `./templates/page/home.html`
   return $vweb.html()
 }

Sum types

This section is empty.

Functions

This section is empty.

Structs

#struct ArrayInit

pub struct ArrayInit {
	// index represent the current element index that is being initialized inside `init`.
	//
	// See [ArrayInit](#ArrayInit) documentation for more info.
	index int
pub:
	// len field represent number of pre-allocated and initialized elements in the array
	//
	// See [ArrayInit](#ArrayInit) documentation for more info.
	len int

	// cap field represent amount of memory space which has been reserved for elements,
	// but not initialized or counted as elements
	//
	// See [ArrayInit](#ArrayInit) documentation for more info.
	cap int

	// init field represent default initializer for each element.
	//
	// See [ArrayInit](#ArrayInit) documentation for more info.
	init element_type
}

Example:

 arr := []int{}
 arr_with_len := []int{len: 1} // [0]
 arr_with_cap := []int{len: 1, cap: 100} // [0]
 arr_with_len_init := []int{len: 1, init: 1} [1]
 arr_with_init := []int{len: 2, cap: 100, init: index * 2} [0, 2]

Array initializer can contain three optional fields:

  1. len – length – number of pre-allocated and initialized elements in the array 2. cap – capacity – amount of memory space which has been reserved for elements, but not initialized or counted as elements 3. init – default initializer for each element

All three fields can be used independently of the others.

cap field

If cap is not specified, it is set to len. cap cannot be smaller than len.

cap can be used for improving performance of array operations, since no reallocation will be needed.

 arr := []int{len: 2}
 arr << 100 // there will be a reallocation that will slow down the program a bit
 

arr_with_cap := []int{len: 2, cap: 10}
 arr_with_cap << 100 // no reallocation

init field

If init is not specified, it is set to 0 for numerical type, '' for string, etc.

 arr := []int{len: 2}
 assert arr == [0, 0]

In init field, you can use special index variable to refer to the current index.

 arr := []int{len: 3, init: index * 2}
 assert arr == [0, 2, 4]

#struct TypeInfo

pub struct TypeInfo {
pub mut:
	idx  int    // index of the type in the type table
	name string // name of the type
}

#struct UnknownCDeclaration

pub struct UnknownCDeclaration {
pub mut:
	unknown_field &UnknownCDeclaration
}

#fn (&UnknownCDeclaration) unknown_method

fn (c &UnknownCDeclaration) unknown_method()

#struct ChanInit

pub struct ChanInit {
pub:
	// cap fields describes the size of the buffered channel.
	//
	// The channel size describes the number of elements that can be
	// written to the channel without blocking.
	// If more elements are written to the channel than the buffer size,
	// then the write is blocked until another thread reads the element
	// from the channel and there is free space.
	//
	// If `cap == 0` (default), then the channel is not buffered.
	//
	// **Example**
	// ```
	// ch := chan int{cap: 10} // buffered channel
	// ch <- 1 // no blocking
	// ```
	//
	// **Example**
	// ```
	// ch := chan int{} // unbuffered channel
	// ch <- 1 // block until another thread reads from the channel
	// ```
	cap int
}

ChanInit describes a chan type initializer.

Example:

 ch := chan int{}
 buf_chan := chan int{cap: 10}

Interfaces

This section is empty.

Enums

#enum CompressionType

pub enum CompressionType {
	zlib
}

CompressionType is the type of compression used for the embedded file.

See [$embed_file] for more details.

#enum FlagEnum

pub enum FlagEnum {}

FlagEnum describes a enum with [flag] attribute.

See Flag attribute for detail.

#fn (FlagEnum) has

fn (f FlagEnum) has(flag FlagEnum) bool

has checks if the enum value has the passed flag.

Example:

 [flag]
 enum Permissions {
   read  // = 0b0001
   write // = 0b0010
   other // = 0b0100
 }
 

fn main() {
   p := Permissions.read
   assert p.has(.read) // test if p has read flag
   assert p.has(.read | .other) // test if *at least one* of the flags is set
 }

#fn (FlagEnum) all

fn (f FlagEnum) all(flag FlagEnum) bool

all checks if the enum value has all passed flags.

Example:

 [flag]
 enum Permissions {
   read  // = 0b0001
   write // = 0b0010
   other // = 0b0100
 }
 

fn main() {
   p := Permissions.read | .write
   assert p.all(.read | .write) // test if *all* of the flags is set
 }

#fn (FlagEnum) set

fn (f FlagEnum) set(flag FlagEnum)

set sets the passed flags.

If the flag is already set, it will be ignored.

Example:

 [flag]
 enum Permissions {
   read  // = 0b0001
   write // = 0b0010
   other // = 0b0100
 }
 

fn main() {
   mut p := Permissions.read
   p.set(.write)
   assert p.has(.write)
 }

#fn (FlagEnum) toggle

fn (f FlagEnum) toggle(flag FlagEnum)

toggle toggles the passed flags.

If the flag is already set, it will be unset.

If the flag is not set, it will be set.

Example:

 [flag]
 enum Permissions {
   read  // = 0b0001
   write // = 0b0010
   other // = 0b0100
 }
 

fn main() {
   mut p := Permissions.read
   p.toggle(.read)
   assert !p.has(.read)
 }

#fn (FlagEnum) clear

fn (f FlagEnum) clear(flag FlagEnum)

clear clears the passed flags.

If the flag is not set, it will be ignored.

Example:

 [flag]
 enum Permissions {
   read  // = 0b0001
   write // = 0b0010
   other // = 0b0100
 }
 

fn main() {
   mut p := Permissions.read
   p.clear(.read)
   assert !p.has(.read)
 }