I want to know the function performed by tokenize in codemirror.
codemirror highlights text by calling a tokenizer function, passing it a context ("state"), and a pointer to the current location in the file that needs to be highlighted ("stream"). The job of this function is to advance the stream past the next token, and to return the type of the token. This is described fairly well in the codemirror api documentation here: http://codemirror.net/doc/manual.html#modeapi
In the case of xml.js (which you referenced in a comment), it has multiple tokenizer functions. Depending on the context, it will set the "tokenize" attribute of the state to refer to one of the tokenizer functions. Then it will use whichever function is pointed by by state.tokenize to find the next token in the stream.
Related
Geogebra seems to be the most intuitive graphic editor. As a bonus, it exposes the construction protocol. But unfortunately, the construction protocol exports only the creation of the objects with their dependencies without additional style information. The information is stored in the XML file, and it is, in principle, accessible. But even then, I cannot figure out how it could be used as input for Geogebra. Is there any way to feed back the modified construction protocol to have Geogebra in a loop until we finish the construction by editing the construction protocol in an outside editor? Would be a "load construction protocol" command enough? And what would be the best channel through which could such a command be fed into Geogebra (AutoHotkey can be a last resort solution, but I would avoid it)?
why
-(void)addSimpleListener:(id<XXSimpleListener>)listener
convert to swift look like this:
func add(_ listener: XXSimpleListener?) {
}
but change the method to this
-(void)addSimpleListener:(id<XXSimpleListening>)listener
and it will convert to this
func addSimpleListener(_ listener: XXSimpleListening?){
}
Xcode (or whatever tool you are using to do the conversion) is merely following Swift API guidelines. Specifically:
Omit needless words. Every word in a name should convey salient information at the use site.
More words may be needed to clarify intent or disambiguate meaning, but those that are redundant with information the reader already possesses should be omitted. In particular, omit words that merely repeat type information.
In the first case, the words SimpleListener in addSimpleListener is repeating the type of the parameter, so they are removed from the method name. However, in the second case, SimpleListener and SimpleListening does not look the same to whatever tool you are using, so it thinks that SimpleListener should be kept.
In my (human) opinion though, I think the method should be named addListener, because:
Occasionally, repeating type information is necessary to avoid ambiguity, but in general it is better to use a word that describes a parameter’s role rather than its type.
Listener is the role of the parameter.
Is there a way to return a struct from an imported function in MQL4, without having to pass it as a parameter and making a memcpy?
Be cautious with any kind of DLL-interfacing, MQL4 Documentation states:
Passing ParametersAll parameters of simple types are passed by values unless it is explicitly indicated that they are passed by reference. When a string is passed, the address of the buffer of the copied string is passed; if a string is passed by reference, the address of the buffer of this string without copying it is passed to the function imported from DLL.Structures that contain dynamic arrays[], strings, classes, other complex structures, as well as static or dynamic arrays[] of the enumerated objects, can't be passed as a parameter to an imported function.When passing an array to DLL, the address of the beginning of the data buffer is always passed (irrespective of the AS_SERIES flag). A function inside a DLL knows nothing about the AS_SERIES flag, the passed array is a static array of an undefined length; an additional parameter should be used for specifying the array size.
More glitches apply... Then how to make it work?
Maybe a straight, heterogeneous multi-party distributed processing, which communicates rather results than function calls, independent of all nightmares of maintaining just DLL-imported functions API changes, is a way safer way to go. Using this approach for the last few years and since than have no problems with New-MQL4.56789 string-s that seized to remain string-s and silently started to become struct-s etc.
Worth to know about.
Anyway, welcome and enjoy the Wild Worlds of MQL4 -- may enjoy to click and read other posts on issues in MQL4/DLL integration and/or signalling/messaging in MQL4 domains. Feel free to ask more
when i connect a signal to a callback function the callback functions gets passed parameters. Is the reference counter increased before the objects get passed to my callback function or do i have to increase it by myself.
I guess there must be some sort of convention for that because nothing like that is mentioned in the documentation of gtk or libgobject.
Generally, you do not assume a reference on an object when it is passed to your callback. You only assume a reference when the object is the return value of a method which is annotated with "transfer full". You can see these annotations in the documentation.
(I say "generally" because there may always be badly constructed libraries whose API violates these guidelines. You can't do a whole lot about that, though.)
How can I extract function body (as a string)? For example I call C function, extract function from stack, check if type is LUA_TFUNCTION and what do I need to do to get its body?
When the function is on the stack, it has already been compiled. The best you can try to do is a lua_dump and then decode the bytecode.
You can call lua_getinfo with a string parameter of "S", then check the "source" member of the lua_Debug structure. If that string starts with '#', it's a filename, and you'll need to re-read the file if you want the source (Lua only read the file incrementally to load the function and never saved it as a string). Otherwise, its contents will be the string loaded as the chunk the function was defined in.
Note that in either case the source returned will be the entire chunk that defined the function in question. You can narrow the string down to only that function using the other fields defined in the structure: note, however, that this is not a guarantee that you will be able to load that string back in to get the same behavior (the function definition may refer to variables defined in an outer scope, for instance).
The Debug library can do this. The Lua C API doesn't have it, you'd want to call a Lua function for this purpose.