I'm looking for a way to inline functions in AS3.
I know that the language itself doesn't offer a native way of doing that but perhaps there is another option:
ANT precompile task
shell script
command line tool
...
Basically, anything that could eventually be integrated with ANT and run on a Hudson CI server.
You can use Joa Ebert Apparat tools to achieve such a thing and more.
You can't inline whatever function you want they are some restrictions
Basically you have to create a new class that extends Macro or Inlined following your need, and declare static function within it, then after running TDSI your function will be inlined.
Check out for example Math inlined function or Macro function
Adobe introduced native inline functions with the new ASC2 compiler in 2012. Use the -inline compiler argument to inline all getters and setters and any functions marked with the new [Inline] metadata. Inlined functions must meet these conditions:
The function is final, static or the containing scope is file or package
The function does not contain any activations
The function does not contain any try or with statements
The function does not contain any function closures
The function body contains less than 50 expressions
http://www.bytearray.org/?p=4789
Related
In Foundry's Slate application, is there a clean way to write functions that accept arguments as input using the handlebar syntax?
Instead of function arguments, inputs to a Slate function are defined by a Handlebar reference inside the Function itself; for example to access data from a query from inside a Function, you might write:
const data = {{q_myQuery}}
Defining dependencies in this way allows Slate to automatically recompute the Function outputs whenever the values of upstream dependencies change. In this way, you never "call" a function, but rather some other element in Slate references the Function output and that output is updated whenever the inputs change.
If you want to do some kind of code reuse you can use functionLibraries to write common code that you can re-use between Functions. These are standard javascript functions that are included in the global javascript scope and can be referenced simply by the function name from any Function and take function parameters using normal javascript syntax. Since these are vanilla javascript you cannot use Handlebars inside a functionLibrary - here any input must be passed in as a parameter from the parent Function.
From the documentation (Slate > Concepts > Functions):
Per-Document level function libraries
Users are able to write reusable javascript functions with parameters. This will assist in the refactoring of code and reducing the copying and pasting of code in functions. You can also re-run and update all the functions dependent on a function library using the Re-run All Function button.
Default JavaScript libraries available
For enhanced use of functions, Slate ships by default (as of Slate 2.15) with the following external JavaScript libraries: Lodash, Math.js, Moment, Numeral and es6-shim. Feel free to use these libraries when writing your functions.Do not use ES6 syntax features unless all users are mandated to use a browser supporting these features.
I am taking a look at the implementation of libsmbclient. The source code I have for samba is 4.1.13. I can find the example testXXX.c functions which shows the examples of using libsmbclient functions. I also found a header file called libsmbclient.h which has all these function prototypes definitions, such as smbc_open, smbc_read and so on. I want to see the really implementation of smbc_open() function, and some other functions. I did grep -r 'smbc_open' *, but I didn't find any place that has the implementation of this function. All I see are the callers calling this function or this prototype definition. So where can I find this function implementation?
I found it. All these smbc_open(), close() ... functions are implemented in libsmb_compat.c
I have a C++ method that takes variable argument as init param. Something like
MyMethod(std::wchar_t*, ...)
Can someone please let me know how can we write a WinRT component wrapper to expose the variable arguments?
WinRT metadata does not support vararg functions, so there is no good way to do this. The answer therefore depends on what the function actually does. Assuming it is some kind of string formatting function I would suggest wrapping it with something like:-
MyMethod(Platform::String^, Windows::Foundation::Collections::IVector<Platform::Object^>^ params);
This will allow you to take the variable arguments.
The problem of course is that this has completely different semantics from what you have. The caller is going to have to pack up an array, and you won't be able to call your existing method easily with the arguments from the vector.
According to documentation (https://developers.google.com/closure/compiler/docs/api-tutorial3#externs), it seems the closure compiler should rename variables when no external declaration exists, including when using functions/variables from an external bit of code. The example they give is
function makeNoteDom(noteTitle, noteContent, noteContainer) {
// Create DOM structure to represent the note.
var headerElement = textDiv(noteTitle);
var contentElement = textDiv(noteContent);
...
}
where the textDiv function is declared in the global scope by a third-party lib of some sort. It says textDiv should be declared external to prevent renaming.
My question is - when I put this code or similar into the Closure Compiler without any extern declarations why is textDiv not renamed (which would break the code), as the documentation indicates?
The compiler assumes that calls to an undefined function are in fact calls to an external functions. Using the command line compiler, you can use --warning_level VERBOSE to have the compiler treat this condition as an error.
The Web Application is primarily built for demos and assumes this by default. While you can set a VERBOSE warning level, it will not change this functionality. See the Additional Web Service Options page for information on options. I've filed a bug report about this.
Due to the renaming algorithm for properties, undeclared properties will be renamed in a breaking way if that same property name isn't declared on an object in externs.
Basically, I want to modify the constructor of the Object
class. Since every class extends Object, I hope whenever any
object of any class is instantiated, the modified function will
be called.
So I did this :
Object.prototype.constructor = function (){
trace("it was called;");
};
and put a breakpoint on the trace statement.
But it didn't stop there.
The trace statement did not get executed also.
Any solutions/suggestions?
In which context are you coding?
If you're using the Flex Compiler MXMLC (default, if you're in FlashBuilder), than you could add the compiler option -es. This should make AS3 feel more like AS2 and JS and support the prototype chain inheritance.
-compiler.es alias -es
"use the ECMAScript edition 3 prototype based object model to allow dynamic overriding of prototype properties. In the prototype based object model built-in functions are implemented as dynamic properties of prototype objects. (advanced)"
I don't know, if this plays well with all the extensions Adobe added to the ECMA Script standard, like packages, namespaces and classes. But you could give it a try.
I don't think it's possible in AS-3, but it was in AS-2.