Skip to content

input_and_output

BlidDev edited this page Jan 9, 2024 · 7 revisions

Overview:

This chapter focuses on the ways you can manage input and output in Niv.


post

usage example:

post

Desc:

Prints out the program's variable stack.

Return value: VOID.

For more complex examples check input_output.nst


print

usage example:

// template
print format Args...

// specific use
print "This doesn't have any trailing args\n"
print "This {}\n" "does"

Args:

  • format: STR
  • Args: List of arguments of any value

Desc:

Prints out the given format and replaces any {} with the corresponding trailing argument.

Return value: VOID.

For more complex examples check (input_output.nst](../blob/main/examples/input_output.nst)


dbg

usage example:

// template
dbg val

// specific use
print "dbg: {}\n" (dbg 4)

Args:

  • val: Any value

Desc:

Returns a string containing the debug info of val, similar to using "{:?}" in Rust.

Return value: STR containing the debug info.

For more complex examples check input_output.nst


prt

usage example:

// template
prt val

// specific use
print "prt: {}\n" (prt 4)

Args:

  • val: Any value

Desc:

Returns a string containing the debug info of val in a "pretty" format, similar to using "{:#?}" in Rust.

Return value: STR containing the pretty debug info.

For more complex examples check input_output.nst


format

usage example:

// template
format format_string Args...

// specific use
set formatted_str (format "hey {}\n" "there")

Args:

  • format_string: STR
  • Args: List of arguments of any value

Desc:

Does the same as print, but instead of printing it to the screen, it returns the formatted string as a variable.

Return value: STR containing the formated string.

For more complex examples check input_output.nst


input

usage example:

// template
input msg, Args...

// specific use
set name  (input "Enter your {}: " "name") 

Args:

  • msg: STR
  • Args: List of arguments of any value

Desc:

Prints the formatted given message in msg and requests input from the user.

Return value: STR containing the user's input.

For more complex examples check input_output.nst


inputcast

usage example:

// template
inputcast type msg Args...

// specific use
set num (inputcast I32 "Enter your {}: ", "age") 

Args:

  • type: STR
  • msg: STR
  • Args: List of arguments of any value

Desc:

Prints the given formated message in msg, requests input from the user, and returns the input casted to the desired type if possible.

Return value: The value of the casted input.

For more complex examples check input_output.nst

Clone this wiki locally