Hey, I think I may finally be converging on a consistant organization for the C code!

parent 784e14d2
#include "duktape/duktape.h"
#include "c_environ.h"
int c_environ(duk_context *ctx) {
#include "bindings_main.h"
void push_bindings_main(duk_context *ctx) {
duk_push_c_function(ctx, c_argv, 0);
duk_put_prop_string(ctx, -2, "argv");
duk_push_c_function(ctx, c_environ, 0);
duk_put_prop_string(ctx, -2, "environ");
}
duk_ret_t c_argv(duk_context *ctx) {
// Construct argv array
duk_idx_t argv_idx = duk_push_array(ctx);
int i = 0;
while (i < mainArgs.argc && i < 100) {
duk_push_string(ctx, mainArgs.argv[i]);
duk_put_prop_index(ctx, argv_idx, i);
i++;
}
return 1;
}
duk_ret_t c_environ(duk_context *ctx) {
int keylen = 0;
char *val;
char *equalsign;
......
#include "duktape/duktape.h"
#include <omp.h>
#include "bindings_openmp.h"
void app_push_openmp(duk_context *ctx) {
duk_push_object(ctx);
void push_bindings_openmp(duk_context *ctx) {
duk_push_c_function(ctx, wrap_omp_get_thread_num, 0);
duk_put_prop_string(ctx, -2, "id");
duk_push_c_function(ctx, wrap_omp_get_num_threads, 0);
......
#include "duktape/duktape.h"
#include "c_argv.h"
int c_argv(duk_context *ctx) {
// Construct argv array
duk_idx_t argv_idx = duk_push_array(ctx);
int i = 0;
while (i < mainArgs.argc && i < 100) {
duk_push_string(ctx, mainArgs.argv[i]);
duk_put_prop_index(ctx, argv_idx, i);
i++;
}
return 1;
}
......@@ -78,14 +78,12 @@ int main(int argc, char *argv[] /* char *environ[] */) {
// Construct the prime argument
duk_push_object(ctx);
// Provide access to some OpenMP thread info
app_push_openmp(ctx);
duk_push_object(ctx);
push_bindings_openmp(ctx);
duk_put_prop_string(ctx, -2, "threadpool");
// Provide access to the environment
duk_push_object(ctx);
duk_push_c_function(ctx, c_argv, 0);
duk_put_prop_string(ctx, -2, "argv");
duk_push_c_function(ctx, c_environ, 0);
duk_put_prop_string(ctx, -2, "environ");
push_bindings_main(ctx);
duk_put_prop_string(ctx, -2, "main");
// Provide access to stdin and stdout
duk_push_object(ctx);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment