Haxe as syntax, how to use AS3 as - haxe

I have this line in AS3 and did not find a proper cast to use.
var ok:LoginOk = msg as LoginOk;
Can someone tell me how to do that in Haxe, LoginOk extends msg.

You can use an unsafe cast:
var ok:LoginOk = cast msg;

Related

Using randomUUID() in Zapier to generate UUID

I'm using Zapier's code module to write some Nodejs to generate a UUID.
I know that I can use node's crypto "library" because I've used it in the past to hash some text (MD5) to send to an API endpoint. I also know that I can use the crypto function randomInt.
For example, the following will correctly without errors return a number in the stated range:
const crypto = require('crypto');
let num = crypto.randomInt(1, 7);
output = [{id: num}];
When I try to use the randomUUID function (documentation), like the following, I get the error "TypeError: crypto.randomUUID is not a function" from Zapier:
const crypto = require('crypto');
let uuid = crypto.randomUUID();
output = [{id: uuid}];
I almost gave up there, but tried one last weird thing:
const crypto = require('crypto');
let uuid = crypto.randomUUID; //changed this
output = [{id: uuid}];
Note that I removed the () and this didn't throw an error and returned something like:
LT6TvivKgpFu5Yk3OvQmti1Hq1aNy5ZM
That looks a lot like a proper UUID since it has the right number of characters, but not the expected hyphens like (for example) 88368f2a-d5db-47d8-a05f-534fab0a0045
So, two questions:
Why is Zapier saying that randomUUID() is not a function? Does it not support this or am I coding something weirdly wrong or not requiring something needed? Is there a different way to do this?
When I use randomUUID (no ()) is this actually a reliable UUID?
EDIT: more info from Zapier, they are saying that their logs show that the code step cannot find module 'uuid'
When I use randomUUID (no ()) is this actually a reliable UUID?
The value you're getting there is not a reliable UUID. UUIDs will contain only 0-9a-f characters, the example you have there doesn't match.
Sorry I can't help you with what's going wrong with the other part! You could maybe try something like this
let crypto;
try {
crypto = require('crypto');
} catch (err) {
console.log('crypto support is disabled!');
}
to make sure the crypto package is actually available and there's not some error being silently suppressed? You may also want to check the version, as randomUUID() appears to have been added in v14.17.0
Also nit but should probably be const uuid = crypto.randomUUID(); instead of let ;)

How can i use ‚momentjs‘ in a ‚binary-parser‘ formatter?

Can anybody help me please. How can i use moment in a formatter?
i think this is not a problem from node or binary parser. it is my understanding i think.
const Parser = require("binary-parser").Parser;
const moment = require('moment');
let time = function(timestamp) {
return moment(timestamp, 'YYMMDDHHmmssSS').format('YYYY-MM-DD HH:mm:ss.SS');
};
let Telegram = new Parser()
.string('timestamp', {encoding: 'hex', length: 7, formatter: time});
The Exception is:
evalmachine.:9
return moment(timestamp, 'YYMMDDHHmmssSS').format('YYYY-MM-DD HH:mm:ss.SS');
^
ReferenceError: moment is not defined
at Parser. (evalmachine.:9:2)
...
I think the Problem is that Parser don't know moment. But how can i realize that?
i have tried to import moment directly in the binary-parser module. But it doesn't working.
If i run moment outside of Parser then it is working.
Maybe anybody can help me.
The formatter function runs without the momentjs context. I am guessing because of the way it consumes the formatter property. In the code found here, the code is:
if (this.code.formatter) {
... (ctx, varName, this.options.formatter)
Because of the funny way the this keyword works, it's bound to the object (options) and because that declaration does not contain momentjs, it says that it is not defined.
You can get a better understanding of this by looking at line 735:
ctx.pushCode("{0} = ({1}).call(this, {0});", varName, formatter);
It's bound to the current object.
P.S.: I copied the code and pasted it on Node.js and it's working perfectly. ^That is a possible explanation.

How to create a Thunderbird native extension?

I need to write an extension for Thunderbird. The extension will be used to do some text mining and relies on native C++ code. From my understanding, Thunderbird extensions are now mostly written in JavaScript and XPCOM is being slowly deprecated (https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM).
Besides, XPCOM seems a bit heavy and I would like an easier path to access my C++ code. Are there any alternatives besides XPCOM to access C++ code from a thunderbird extension?
Thanks!
Take a look at js-ctypes (https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes)
Little example:
Components.utils.import("resource://gre/modules/FileUtils.jsm");
Components.utils.import("resource://gre/modules/ctypes.jsm")
// path to C++ lib (/home/username/.thunderbird/PROFILE/extensions/EXTNAME/components/lib.so)
var libPath = FileUtils.getFile("ProfD", ["extensions", "EXTNAME", "components", "lib.so"]);
var lib = ctypes.open(libPath.path);
var libFunction = lib.declare("concatStrings", // function name in C++ code
ctypes.default_abi,
ctypes.char.ptr, // return value
ctypes.char.ptr, // param1
ctypes.char.ptr // param2
);
var ret = libFunction("abc", "efg");
lib.close()
Also be aware that C++ compiler does name mangling due to function overloading so your function name might be 'concatStrings' in C++ code, but then in assembly it might be something like '_123concatStrings'. To prevent this declare your function like:
extern "C" const char * concatStrings ( const char * str1, const char * str2 );

Python's 'from ... import *' in Node.js

Is there anything equivarent to Python's 'from foobar import *' in Node.js?
Now I wrote the following code:
var foobar = require('foobar'),
func1 = foobar.func1,
gvar2 = foobar.gvar2,
const3 = foobar.const3;
I think this is ugly, because a lot of names appeared twice.
Python provides smart solution which removes duplications:
from foobar import func1, gvar2, const3
Does Node.js provide similar way?
No, it does not; at least, I am not aware of any way to do this easily.
Node uses the CommonJS module system, which requires a function, require, that returns an exported API for a module.
function mixin(mod,scope)
{
if (!scope)
scope=global;
var module = require(mod);
for (key in module)
scope[key] = module[key];
}
mixin('http');
var s = createServer();

instantiate sound clips dynamically in as3

How can i call and instantiate soundclips in my library dynamically
here is the code i have so far
function soundbutton_Handler (e:MouseEvent):void {
trace(e.target.name);
var mySound:Sound = new e.target();
mySound.play();
}
and the error i get is :
Error #1007: Instantiation attempted on a non-constructor.
at quiz_fla::MainTimeline/soundbutton_Handler()
I got it, for future reference if any one needs help i 'm posting the solution here
var classRef:Class = getDefinitionByName(e.target.name) as Class;
var mysound:Sound = new classRef();
mysound.play();

Resources