Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
download.c File Reference

Fun VM opcode snippet: HTTP download to file via libcurl (OP_CURL_DOWNLOAD). More...

Go to the source code of this file.

Functions

 free_value (a)
 free_value (b)
 push_value (vm, make_int(0))

Variables

case OP_CURL_DOWNLOAD
Value b = pop_value(vm)
 break

Detailed Description

Fun VM opcode snippet: HTTP download to file via libcurl (OP_CURL_DOWNLOAD).

This snippet is included by vm.c and implements the OP_CURL_DOWNLOAD instruction. When FUN_WITH_CURL is enabled, it downloads the content at the given URL and writes it to the specified filesystem path.

Stack behavior:

  • Pops: path:string, url:string (values are converted via value_to_string_alloc)
  • Pushes: int (1 on success, 0 on error or when CURL is disabled)

Pops a destination path and URL, streams the HTTP response body into the file, and pushes 1 on success or 0 on any error. Without FUN_WITH_CURL, behaves as a no-op that consumes two values and pushes 0.

Error handling:

  • Returns 0 if URL/path conversion fails, file open fails, CURL init or perform fails.
  • Follows redirects (CURLOPT_FOLLOWLOCATION = 1L).
  • Writes via fun_curl_file_write_cb directly into the opened FILE*.

Notes:

  • All temporary allocations (URL, path) are freed; FILE* is closed.
  • On builds without FUN_WITH_CURL, consumes two values and pushes 0.

Definition in file download.c.

Function Documentation

◆ free_value() [1/2]

free_value(a)

◆ free_value() [2/2]

free_value(b)

◆ push_value()

push_value(vm,
make_int(0) )

Variable Documentation

◆ b

Value b = pop_value(vm)

Definition at line 84 of file download.c.

◆ break

break

Definition at line 88 of file download.c.

◆ OP_CURL_DOWNLOAD

case OP_CURL_DOWNLOAD

Definition at line 38 of file download.c.