|
|
|
@ -31,6 +31,7 @@
@@ -31,6 +31,7 @@
|
|
|
|
|
#include "util.h" |
|
|
|
|
#include "markdown.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const std::string SITE_CONFIG_FNAME = "stgen.json"; |
|
|
|
|
const std::string DEFAULT_PUBLISH_ROOT = "public"; |
|
|
|
|
const std::string DEFAULT_SOURCE_DIR = "."; |
|
|
|
@ -58,6 +59,69 @@ struct runtime_config {
@@ -58,6 +59,69 @@ struct runtime_config {
|
|
|
|
|
runtime_config settings; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace duk { |
|
|
|
|
extern "C" { |
|
|
|
|
#include <duk_config.h> |
|
|
|
|
#include <duktape.h> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class duktape { |
|
|
|
|
duk_context *ctx; |
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
duktape() { |
|
|
|
|
ctx = duk_create_heap_default(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
~duktape() { |
|
|
|
|
duk_destroy_heap(ctx); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void compile_file(std::string fname)
|
|
|
|
|
{ |
|
|
|
|
std::string file = read_file(fname); |
|
|
|
|
if (duk_pcompile_lstring(ctx, 0, file.c_str(), file.length()) != 0) { |
|
|
|
|
std::cout << "Error :" << duk_safe_to_string(ctx, -1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void compile_text(std::string file)
|
|
|
|
|
{ |
|
|
|
|
if (duk_pcompile_lstring(ctx, 0, file.c_str(), file.length()) != 0) { |
|
|
|
|
std::cout << "Error :" << duk_safe_to_string(ctx, -1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void run() |
|
|
|
|
{ |
|
|
|
|
duk_call(ctx, 0); |
|
|
|
|
std::cout << "program result: " << duk_safe_to_string(ctx, -1); |
|
|
|
|
duk_pop(ctx); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void test() { |
|
|
|
|
compile_file("katex.min.js"); |
|
|
|
|
duk_call(ctx, 0); |
|
|
|
|
duk_pop(ctx); |
|
|
|
|
std::string line = "katex.renderToString(\"c = \\pm\\sqrt{a^2 + b^2}\", {throwOnError: false });"; |
|
|
|
|
duk_push_lstring(ctx, line.c_str(), line.length()); |
|
|
|
|
if (duk_peval(ctx) != 0) { |
|
|
|
|
std::cout << "Error (test):" << duk_safe_to_string(ctx, -1); |
|
|
|
|
} else { |
|
|
|
|
std::cout << "Result :" << duk_safe_to_string(ctx, -1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
duk_pop(ctx); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Fork and exec a command given in args taking input from in and sending
|
|
|
|
@ -858,6 +922,12 @@ int main(int argc, char **argv) {
@@ -858,6 +922,12 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
|
|
auto cmd_options = parse_options(argc, argv); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
duk::duktape d {}; |
|
|
|
|
d.test(); |
|
|
|
|
|
|
|
|
|
exit(0); |
|
|
|
|
|
|
|
|
|
stgen::builder b (cmd_options); |
|
|
|
|
b.build(); |
|
|
|
|
|
|
|
|
|