-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
file exists function help #12186
Comments
You probably should look at these pages of the docs, which will let you create a JS function which you can call from your C code. That JS function can then use the Node API to check if the file exists. |
@curiousdannii #include "/usr/lib/emscripten/system/include/emscripten.h"
#include <string>
using namespace std;
#ifndef EM_PORT_API
# if defined(__EMSCRIPTEN__)
# include <emscripten.h>
# if defined(__cplusplus)
# define EM_PORT_API(rettype) extern "C" rettype EMSCRIPTEN_KEEPALIVE
# else
# define EM_PORT_API(rettype) EMSCRIPTEN_KEEPALIVE
# endif
# else
# if defined(__cplusplus)
# define EM_PORT_API(rettype) extern "C" rettype
# else
# define EM_PORT_API(rettype) rettype
# endif
# endif
#endif
//EMSCRIPTEN_KEEPALIVE void hi(const char* p){
EM_PORT_API(int) hi(const char* p){
// string a = "function show(arg){console.log(arg);};";
string b = p;
// string c = "show(\"";
// string d = "\");";
//
string test = "const fs = require('fs');";
string a = "function show(arg){let check = fs.existsSync(arg";
string d = ");if(check){return 1}else{return 0};};show(\"";
string e = "\");";
// string run = a+c+p+d;
string run = test+a+d+b+e;
int num = emscripten_run_script_int(run.c_str());
return num;
} compile and do test for node is correct var em_module = require('./run.js');
em_module['onRuntimeInitialized'] = onRuntimeInitialized;
//console.log(em_module.run());
//em_module._hi('qweqwe');
function onRuntimeInitialized(){
var s = '/home/wingdust/Programming/Emcc/for.txt';
let a = em_module.ccall('hi','number',['string'],[s])
console.log(a)
} But I want use it for electron+typescript+vite ,problem show up /// <reference types="emscripten"/>
interface em_moduel extends EmscriptenModule {
ccall:typeof ccall;
hi(arg:string):number;
} And In Electron code /// <reference types="emscripten"/>
let em_moudle = require("../cplusplus/run.js")
em_moudle['onRuntimeInitialized'] = onRuntimeInitialized
function onRuntimeInitialized() {
let a = '../assets/electron.png'
let b = em_moudle.ccall('hi','number',['string'],[a])
console.log(b);
}
It' has any experience to how to use wasm file for Electron |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant. |
emscripten version :2.0.1
I try to write a
C++
function for validate file exists.here is my code
Actually I write for run in Electron
but I don't how to use it after I compiled it get
a.out.js a.out.wasm
Mostly I saw the example is for web or use
node test.js
can help me ?
or this function can achieve another way
The text was updated successfully, but these errors were encountered: