I'm new and struggling with velocity templates. I have few templates in hand with lots of macros in it.
// file b.vm
#macro (bmacro)
from b macro
#end
// file a.vm
#parse("//temp//b.vm")
from a
#bmacro()
My expectation is to get
from a
from b macro
however, I am getting only "from a" as outcome. But when I place any static text outside bmacro, it is getting along.
By the way, I'm using NVelocity from castle project.
Thanks
The macro doesn't work because NVelocity (and its ancestor Velocity) determine if #bmacro is a directive or macro at parse time, while the #bmacro macro gets discovered at runtime as it jumps into the other template, and so it is passed through as text.
I answered this other question with a detailed answer a few months ago that had the same problem:
macros not rendering in NVelocity
Related
Lately I was creating some global functions inside of Bluprint Function Library (BPFL) and I've noticed that when I call function inside of another function that is also created in same BPFL, World Context Object Reference input pin will appear on the node. This pin doesn't need to be plugged and all the functions will compile without any errors or even warnings.
I've searched for the answear but I wasn't able to find any. I've found only UE-39873 bug ticket which exacly describes this behavior and pull request 8016 that would fix it but It has been resolved as 'Won't fix' without any reason given.
You can even quickly reproduce it by following these steps:
Create blank UE project and open Editor
Create new Blueprint Function Library
Create new function inside of Blueprint Function Library
Call the same function inside of it's own body
World Context Object Reference input pin should appear on function node
(UE5.0.3 / Epic Launcher version)
So my question is:
Why does World Context pin appear in this specific case and what is the purpose of using it?
Thanks in advance for any explanation!
This question has been answered on UnrealEngine Forum
Thats nothing you should worry about (if gives you an error just connect it with the world context variable).
But basicly, every function that comes from a function library (not from an actor), needs to have a reference in the world to be executed. That’s why it appears, when you call a function from a class that comes from the the class actor it will assume that the world context is the actor itself, that’s why it not appears in characters and actors, it still there but it just not visible.
And additionally here:
When function libraries need a reference of the world sometimes for some tasks…
for example get all actors with some tag…the function need to know the world where those actors are…or a delta time, etc.
There is a way to tell the library function to use the actor that is calling it as world context object so the world context pin does not appears in the blueprint node and is adding the meta WordlContext.
As I'm not allowed to add an answer to several duplicated questions, I will ask this question and give also one answer ;-)
The undefined symbol was a call to a self written swift function. This function sits in an swift file with only "global" functions (no class in that file). The function is called from several classes and all was good until this morning.
Suddenly I got this link-error message when producing the release product. The funny think was, it was only for ONE function call. All other calls got no errors, and when I commented out this particular function call, all was good. And this function is a very easy one. There is only one function parameter (Int64) and it returns a CLocationCoordinate2D.
I checked all possible solutions found here and at other places in the web. I even copied the function 1:1 as a local function inside the class.. nothing worked.
The final solution was the compiler flag for optimization. For release builds the flag in "Swift Compiler - Code Generation" is set to "Fast, Whole Module Optimization".
After changing that to "Fast, Single Module Optimization", everything worked ...
I think it is simply a bug in the optimization engine.
.. maybe that will help others in similar situations.
I'm doing some competitions on a website called topcoder.com where the objective is to solve algorithmic problems. I'm using Eclipse for this purpose, and I code in Java, it would be help me to have some predefined templates or macros that I can use for common coding tasks. For example I would like to write methods to be able to find the max value in and int[] array, or the longest sequence in an int[] array, and so on (there should be quite many of these). Note I can't write these methods as libraries because as part of the competition I need to submit everything in one file.
Therefore ideally, I would like to have some shortcut available to generate code both as a method and as a calling statement at once. Any ideas if this is possible?
Sure you can - I think that's a nifty way to auto-insert boilerplate or helper code. To the point of commenters, you probably want to group the code as a helper class, but the general idea sounds good to me:
You can see it listed in your available templates:
Then as you code your solution, you can Control+Space, type the first few characters of the name you gave your template, and you can preview it:
And then you can insert it. Be sure if you use a class structure to position it as an inner class:
Lastly - if you want to have a template inserts a call to method from a template, I think you would just use two templates. One like shown above (to print the helper code) and another that might look like this, which calls a util method and drops the cursor after it (or between the parentheses if you'd like, etc):
MyUtils.myUtilMethod1();${cursor}
Working with Rails 3.1 (rc5), and I'm noticing that any coffeescript file I include rails (or sprockets) is adding in initializing javascript at the top and bottom. In other words, a blank .js.coffee file gets outputted looking like this:
(function() {
}).call(this);
This is irritating because it screws up my javascript scope (unless I really don't know what I'm doing). I generally separate all of my javascript classes into separate files and I believe that having that function code wrapping my classes just puts them out of scope from one another. Or, atleast, I can't seem to access them as I am continually getting undefined errors.
Is there a way to override this? It seems like this file in sprockets has to do with adding this code:
https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/jst_processor.rb
I understand that wrapping everything in a function might seem like an added convenience as then nothing is ran until DOM is loaded, but as far as I can tell it just messes up my scope.
Are you intending to put your objects into the global scope? I think CoffeeScript usually wraps code in anonymous functions so that it doesn't accidentally leak variables into the global scope. If there's not a way to turn it off, your best bet would probably be to specifically add anything you want to be in the global scope to the window object:
window.myGlobal = myGlobal;
It seems to be a javascript best practice these days to put code inside a function scope and be explicit about adding objects to the global scope, and it's something I usually see CoffeeScript do automatically.
You don't want to put everything into the global scope. You want a module or module like system where you can namespace things so you don't colide with other libraries. Have a read of
https://github.com/jashkenas/coffee-script/wiki/Easy-modules-with-coffeescript
I have a comment template in Eclipse (CDT) that I use for function calls which looks like:
//****************************************************************************
//
// Function: ${enclosing_method}
//
// Purpose:
//
// Parameters:
//
//****************************************************************************
My problem is that the ${enclosing_method} template variable doesn't work MOST of the time, but other times it does and I have yet to figure out why. I've tried using the comment template inside of the function and outside (on top of) the function definition even within the same header file. I prefer it to be on top and have seen it work in that position but again I don't know why.
What prerequisites need to be met in order for the enclosing_method variable to place the name within the comment automagically?
Thanks in advance for any insight you can provide.
You are not the only one experiencing issues with this template.
Even in JDT (Java) there is a problem, since 2004! See bug 76661.
It is however not entirely reproducible.
Looked into this to try and find a reproducible case. I can get it happen consistently if I add a new method to a class and then execute the template inside of the method before saving
So far, no patch in sight.