73 lines
2.0 KiB
C++
73 lines
2.0 KiB
C++
#include "uce_lib.h"
|
|
#include <functional>
|
|
#include <map>
|
|
#include <tuple>
|
|
|
|
extern "C" void phase3_core_print(const char* data, size_t len);
|
|
extern "C" void phase3_core_invoke_callback(void (*cb)(int), int value);
|
|
extern "C" void phase3_core_invoke_function(std::function<int(int)>* f, int value);
|
|
extern "C" int phase3_helper_state_plus(int value);
|
|
|
|
int phase3_unit_state = 40;
|
|
int phase3_weak_data __attribute__((weak)) = 0;
|
|
|
|
static void phase3_unit_callback(int value)
|
|
{
|
|
String out = "<p>callback=" + std::to_string(value + phase3_unit_state) + "</p>\n";
|
|
print(out);
|
|
}
|
|
|
|
#ifndef UCE_SET_CURRENT_REQUEST_DEFINED
|
|
#define UCE_SET_CURRENT_REQUEST_DEFINED
|
|
|
|
/*load_declarations*/
|
|
|
|
extern "C" void __uce_set_current_request(Request* _request)
|
|
{
|
|
context = _request;
|
|
/*load_units*/
|
|
}
|
|
|
|
#endif
|
|
#line 4 "spikes/wasm-phase3/page.uce"
|
|
extern "C" void __uce_render(Request& context)
|
|
{
|
|
print(R"(<section class="phase3">
|
|
<h1>PHASE3 PAGE OK</h1>
|
|
<p>host=)");
|
|
print(html_escape(context.params["HTTP_HOST"]));
|
|
print(R"(</p>
|
|
<p>route=)");
|
|
print(html_escape(context.call["route"].to_string()));
|
|
print(R"(</p>
|
|
<p>answer=)");
|
|
print(html_escape(context.call["nested"]["answer"].to_string()));
|
|
print(R"(</p>
|
|
)");
|
|
context.call["nested"].each([&](const DValue& value, String key) {
|
|
print(R"( <p>each=)");
|
|
print(html_escape(key + ":" + value.to_string()));
|
|
print(R"(</p>
|
|
)");
|
|
});
|
|
print(R"( <p>self-got=)");
|
|
phase3_weak_data = 7;
|
|
print(std::to_string(phase3_helper_state_plus(2) + phase3_weak_data - 7));
|
|
print(R"(</p>
|
|
)");
|
|
std::map<String, String> phase3_map;
|
|
phase3_map.emplace(std::piecewise_construct, std::forward_as_tuple("piece"), std::forward_as_tuple("wise"));
|
|
print(R"( <p>map=)");
|
|
print(html_escape(phase3_map["piece"]));
|
|
print(R"(</p>
|
|
)");
|
|
phase3_core_invoke_callback(phase3_unit_callback, 2);
|
|
void (*volatile print_ptr)(const char*, size_t) = phase3_core_print;
|
|
print_ptr("<p>got-func-ok</p>\n", 19);
|
|
auto* fn = new std::function<int(int)>([](int value) { return(value * 3); });
|
|
phase3_core_invoke_function(fn, 14);
|
|
delete fn;
|
|
print(R"( </section>
|
|
)");
|
|
}
|