-
Notifications
You must be signed in to change notification settings - Fork 21
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
Build instructions, console mode, require calls #1
Comments
Hi, many thanks for contributing. it's so glad that you are trying to use this project. :) the issues and the questions.. Supporting Windows XPgreat work! please make Pull-Requests! Q1. static link and stdoutin node.js world(as like other *nix world) stdout/stderr are so much important. solution 1 - wrapping 'console' var console = {
log : function() {
// handle here in js
// test
require('fs').appendFileSync('stdout.log', arguments[0]);
}
};
console.log('hi', 'there'); solution 2 - managing stdout pipe in delphi solution 3 - making tobynode.dll(including pipe handling) as BPL! about 'loading tobynode.dll dynamically' you suggested, Q2. requireit's possible to intercept 'require' but so tricky. const script = `global.__filename = ${JSON.stringify(name)};\n` +
'global.exports = exports;\n' +
'global.module = module;\n' +
'global.__dirname = __dirname;\n' +
'global.require = require;\n' +
'return require("vm").runInThisContext(' +
`${JSON.stringify(body)}, { filename: ` +
`${JSON.stringify(name)}, displayErrors: true });\n`; tobynode.dll 's loading steps are.. I also desire that node'js core team supports one tarred/zipped node_modules file. solution 1 - modify node.js(a long long road) to support kinda memory filesystem(?)
solution 2 - using require.cache
solution 3 - including modules into custom_tobynode.dll l(hack node.js and rebuild)
Q3. unload/reload tobynode.dllooops. we can add 'uncaughtexception handler' in tobyOnLoad() // Don't quit on fatal error.
process.on('uncaughtException', function (error) {
// Do nothing if the user has a custom uncaught exception handler.
var dialog, message, ref, stack
if (process.listeners('uncaughtException').length > 1) {
return
}
// Show error in GUI.
dialog = require('electron').dialog
stack = (ref = error.stack) != null ? ref : error.name + ': ' + error.message
message = 'Uncaught Exception:\n' + stack
dialog.showErrorBox('A JavaScript error occurred in the main process', message)
}) I think it's better to separate them into each issues. as small as possible. :) using node.js in delphi give us a lots of opportunities. please, let me know if I'm wrong in some point. |
Hello, I have made TobyPascal with dynamic linking, it works well on Windows 10, but for some reason is failing on Windows XP even in console application.
Error is raised in thread created by tobynode.dll So can't fully get rid of using console application. I think tobynode.dll should allocate dummy pipes for The js code from the example works ok in non console application. But this code will fail:
Error happens because core node.js code in Also interesting, is it possible to build
I agree with you. Also I like the idea to share Delphi's VCL or Firemonkey to js code. |
The reason why |
sorry for the late reply. recently, I had no time to code. TTimer,for reading redirected stdout, need to be refactored as Thread or Async/Event. |
It's better to open new issues for each subjects. |
Hello,
thank you for work and for great example how to embed node.js into delphi application.
Here https://github.com/ivere27/toby we can find instructions how to build c++ application that embeds node.js.
But there are no instructions how to build
tobynode.dll
for use with Delphi. It may be hard for some one from Delphi world to build something in Visual Studio.By the way, main page of this repository suggest downloading debug version of
tobynode.dll
:https://github.com/ivere27/archive/tree/master/tobynode/node_v6.10.0_x_toby_v0.1.5_x86_debug
This dll works only if Visual Studio is installed. Or you need to collect and copy to application folder some dll-s from the debug version of visual studio redistributable package.
This solution https://github.com/ivere27/toby/tree/master/vc_tobynode has only debug configuration setup. When I tell Visual Studio to build release version of
tobynode.dll
- it doesn't builds, because release configuration is not set (folders, linker and compiler settings).I wanted to build release and optimized version of tobynode.dll that doesn't require installing C++ redistributable packages.
After lots of hours finally I managed to build release version of tobynode.dll, but it was only 53 kb and required
node.dll
and redistributable package.Also I figured out that node.js 6 and above does not support Windows XP, but my delphi application needs WinXP support.
The good news is that tobynode support node.js 5.11 and node.js 5.11 support Windows XP!
Finally I managed to build tobynode.dll with node.js 5.11 inside, it is almost 9 Mb in size. I tested it on Windows XP SP3 without any redistributable packages, and it works.
I think it will be good to share this dll with others:
tobynode.zip - release version, node.js 5.11
Here is solution with release configuration to build this dll:
vc_tobynode.zip
Folder structure should be the same as described here for building C++ sample.
Unsure if I configured this solution correctly, because I am not familiar with C++, may be it misses some parts, but all node.js features I tested - worked.
I have some additional questions, unsure if I should create separate issue for each or not.
TToby
class does not help, console should be allocated before tobynode.dll loads. So the question is:How to use
tobynode.dll
not in console application?Core node.js code throws errors when there are no stdout or stderr even if
console.log(...)
is not called from javascript. For example node.js source filenode\lib\net.js
has this code:if (this !== process.stderr)
This code only checks if current stream is not stderr, nothing was going to be logged, but code is failing not in console application.
I suggest modifying
TToby
class to load tobynode.dll dynamically, so we can setup stdout and stderr pipes before loading tobynode.dll.require
call? I want to embed some third party node modules to my application, but I do not want them to be stored innode_modules
folder in application directory. I want to store third-party modules that are loaded throughrequire
call as resources of main executable (or at least inside tobynode.dll). Can I achieve this without modifying node.js sources and rebuildingtobynode.dll
when I need to embed some new module?Thanks!
The text was updated successfully, but these errors were encountered: