Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
get.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
38
40#ifdef FUN_WITH_CURL
41 Value vurl = pop_value(vm);
42 char *url = value_to_string_alloc(&vurl);
43 free_value(vurl);
44 if (!url) {
45 push_value(vm, make_string(""));
46 break;
47 }
48 FunCurlBuf buf = {NULL, 0};
49 CURL *h = curl_easy_init();
50 if (!h) {
51 free(url);
52 push_value(vm, make_string(""));
53 break;
54 }
55 curl_easy_setopt(h, CURLOPT_URL, url);
56 curl_easy_setopt(h, CURLOPT_FOLLOWLOCATION, 1L);
57 curl_easy_setopt(h, CURLOPT_WRITEFUNCTION, fun_curl_write_cb);
58 curl_easy_setopt(h, CURLOPT_WRITEDATA, &buf);
59 CURLcode rc = curl_easy_perform(h);
60 curl_easy_cleanup(h);
61 free(url);
62 if (rc != CURLE_OK) {
63 if (buf.d) free(buf.d);
64 push_value(vm, make_string(""));
65 break;
66 }
67 Value s = make_string(buf.d ? buf.d : "");
68 if (buf.d) free(buf.d);
69 push_value(vm, s);
70#else
71 Value v = pop_value(vm);
74#endif
75 break;
76}
@ OP_CURL_GET
Definition bytecode.h:173
Value v
Definition cast.c:22
int rc
push_value(vm, make_string(""))
free_value(v)
char * buf
Definition input_line.c:103
free(vals)
uint32_t s
Definition rol.c:31
Tagged union representing a Fun value.
Definition value.h:68
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
Definition value.c:95
char * value_to_string_alloc(const Value *v)
Allocate a printable C string for a Value.
Definition value.c:641