Skip to content

YmStrip/vite-cpp-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STEP

  1. put in vite plugin and install node-gyp , deps
  2. import

ts & vue

<template>
  <Button @click="test()"></Button>
</template>
<script lang="ts" setup>
import api from "./hello.cc"
const test = () => {
  api.hello()
}
</script>

c

#include <napi.h>

Napi::String Method(const Napi::CallbackInfo &info) {
	Napi::Env env = info.Env();
	return Napi::String::New(env, "world");
}
Napi::Number sum(const Napi::CallbackInfo &info) {
	auto env = info.Env();
	auto v0 = info[0].As<Napi::Number>().DoubleValue();
	double a = 0;
	for (int i = -1; ++i < v0;) {
		a += i;
	}
	return Napi::Number::New(env, a);
}
Napi::Object Init(Napi::Env env, Napi::Object exports) {
	exports.Setting(Napi::String::New(env, "hello"),
	                Napi::Function::New(env, Method));
	exports.Setting(Napi::String::New(env, "sum"),
									Napi::Function::New(env, sum));
	return exports;
}

NODE_API_MODULE(hello, Init);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published