mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
deno2: pass argv to js
This commit is contained in:
parent
ec65717c59
commit
f92f10b848
3 changed files with 25 additions and 6 deletions
|
@ -24,9 +24,9 @@ IN THE SOFTWARE.
|
|||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include "v8/src/base/logging.h"
|
||||
#include "v8/include/libplatform/libplatform.h"
|
||||
#include "v8/include/v8.h"
|
||||
#include "v8/src/base/logging.h"
|
||||
|
||||
#include "./deno_internal.h"
|
||||
#include "include/deno.h"
|
||||
|
|
|
@ -20,7 +20,13 @@ window["denoMain"] = () => {
|
|||
startMainJs: mainJs,
|
||||
startMainMap: mainMap
|
||||
} = msg;
|
||||
|
||||
denoPrint(`cwd: ${cwd}`);
|
||||
denoPrint(`debugFlag: ${debugFlag}`);
|
||||
|
||||
for (let i = 0; i < argv.length; i++) {
|
||||
denoPrint(`argv[${i}] ${argv[i]}`);
|
||||
}
|
||||
};
|
||||
|
||||
function typedArrayToArrayBuffer(ta: Uint8Array): ArrayBuffer {
|
||||
|
|
|
@ -5,30 +5,43 @@
|
|||
#include <unistd.h>
|
||||
#include <string>
|
||||
|
||||
#include "v8/src/base/logging.h"
|
||||
#include "./msg.pb.h"
|
||||
#include "include/deno.h"
|
||||
#include "v8/src/base/logging.h"
|
||||
|
||||
static char** global_argv;
|
||||
static int global_argc;
|
||||
|
||||
void MessagesFromJS(Deno* d, const char* channel, deno_buf buf) {
|
||||
printf("MessagesFromJS %s\n", channel);
|
||||
|
||||
char cwdbuf[1024];
|
||||
std::string cwd(getcwd(cwdbuf, sizeof(cwdbuf)));
|
||||
|
||||
deno::Msg response;
|
||||
response.set_command(deno::Msg_Command_START);
|
||||
|
||||
char cwdbuf[1024];
|
||||
std::string cwd(getcwd(cwdbuf, sizeof(cwdbuf)));
|
||||
response.set_start_cwd(cwd);
|
||||
|
||||
for (int i = 0; i < global_argc; ++i) {
|
||||
printf("arg %d %s\n", i, global_argv[i]);
|
||||
response.add_start_argv(global_argv[i]);
|
||||
}
|
||||
printf("response.start_argv_size %d \n", response.start_argv_size());
|
||||
|
||||
std::string output;
|
||||
CHECK(response.SerializeToString(&output));
|
||||
|
||||
auto bufout = deno_buf{output.c_str(), output.length()};
|
||||
deno_buf bufout{output.c_str(), output.length()};
|
||||
deno_set_response(d, bufout);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
deno_init();
|
||||
|
||||
deno_set_flags(&argc, argv);
|
||||
global_argv = argv;
|
||||
global_argc = argc;
|
||||
|
||||
Deno* d = deno_new(NULL, MessagesFromJS);
|
||||
bool r = deno_execute(d, "deno_main.js", "denoMain();");
|
||||
if (!r) {
|
||||
|
|
Loading…
Reference in a new issue