mirror of
https://onedev.site.tesses.net/crosslang/crosslangextras
synced 2026-02-08 17:15:45 +00:00
Add publish to crosslang and add plugin_host support for packages
This commit is contained in:
76
Tesses.CrossLang.BuildEssentials/res/cppfiletemplate.cpp
Normal file
76
Tesses.CrossLang.BuildEssentials/res/cppfiletemplate.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <CrossLang.hpp>
|
||||
#include "@<<HEADER>>@.h"
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::CrossLang;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::string name = argv[0];
|
||||
Tesses::Framework::Filesystem::LocalFilesystem fs;
|
||||
Tesses::Framework::Filesystem::VFSPath exePath=fs.SystemToVFSPath(name);
|
||||
exePath.MakeAbsolute();
|
||||
|
||||
|
||||
TF_InitWithConsole();
|
||||
|
||||
GC gc;
|
||||
gc.Start();
|
||||
GCList ls(gc);
|
||||
TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls));
|
||||
|
||||
TStd::RegisterStd(&gc,env);
|
||||
{
|
||||
auto ms = std::shared_ptr<Tesses::Framework::Streams::MemoryStream>(false);
|
||||
auto& buff = ms->GetBuffer();
|
||||
buff.resize(@<<CAPS_VERSION>>@_length);
|
||||
memcpy(buff.data(),@<<CAPS_VERSION>>@_data,@<<CAPS_VERSION>>@_length);
|
||||
auto file = TFile::Create(ls);
|
||||
file->Load(&gc, &ms);
|
||||
env->LoadFile(&gc,file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(env->HasVariable("WebAppMain"))
|
||||
{
|
||||
Args args(argc, argv);
|
||||
int port = 4206;
|
||||
for(auto& item : args.options)
|
||||
{
|
||||
if(item.first == "port")
|
||||
{
|
||||
port = std::stoi(item.second);
|
||||
}
|
||||
}
|
||||
TList* args2 = TList::Create(ls);
|
||||
args2->Add(exePath.ToString());
|
||||
for(auto& item : args.positional)
|
||||
{
|
||||
args2->Add(item);
|
||||
}
|
||||
|
||||
auto res = env->CallFunction(ls, "WebAppMain", {args2});
|
||||
TObjectHttpServer http(&gc, res);
|
||||
Tesses::Framework::Http::HttpServer svr(port,http,false);
|
||||
|
||||
svr.StartAccepting();
|
||||
TF_RunEventLoop();
|
||||
TDictionary* _dict;
|
||||
if(GetObjectHeap(res,_dict))
|
||||
{
|
||||
_dict->CallMethod(ls,"Close",{});
|
||||
}
|
||||
TF_Quit();
|
||||
}
|
||||
else {
|
||||
TList* args = TList::Create(ls);
|
||||
args->Add(exePath.ToString());
|
||||
for(int arg=1;arg<argc;arg++)
|
||||
args->Add(argv[arg]);
|
||||
auto res = env->CallFunction(ls,"main",{args});
|
||||
int64_t iresult;
|
||||
if(GetObject(res,iresult))
|
||||
return (int)iresult;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user