SWIG precompiled libraries - swig

I've received a set of 3rd party .lib files and a single .h file which I want to wrap using SWIG so I can use in another language. All SWIG's examples are with the C\C++ source code, but in my case I don't have the source code.
What should I do different to create the wrapper?

While the SWIG examples may include definitions (source code) to allow the reader to compile and try them, you will notice that all examples of interface files (.i) only contain declarations (what you typically find in a header file), which is all SWIG needs to create a wrapper.
The normal way of writing an interface file goes like this:
/* File : example.i */
%module example
%{
/* This block will end up verbatim in the generated wrapper - include your header
* so that the wrapper will have access to its definitions
*/
#include "your_header.h"
%}
/* The definitions in this part are used to generate the wrapper.
* Copy the definitions you want to export to the other language from the header
* and put them here
*/
extern double variable_from_header;
extern int function_from_header(int);
If your header file is simple and you want to export every definition in it, you might get away with an interface file that looks like this:
/* File : example.i */
%module example
%{
#include "your_header.h"
%}
%include "your_header.h"
Notice the %include directive which instructs SWIG to parse the included file as if it were part of the interface definition file. See also Section 5.7 of the manual that discusses this approach.
Once you have your wrapper, you link it with the lib as you would link the objects created from the source code in the examples.

Related

Organizing code in HTML

So I'm self studying HTML and I was wondering if there's a way to organize my code in a better way, like when you use pragma region and pragma endregion in C++.
I'm really looking for something to be as simple as that, to be 2 or maybe 3 code lines at best.
For those who doesn't know C++, pragma is used like this:
#pragma region NameOfMyRegion
// Code....
#pragma endregion
And then you can just expand and collapse it as you wish, and the name of the region will be what is displayed instead of the whole bunch of code section in the region. The example is in this link: http://pho.to/9Z7LB
Looking for something as super simple, because I only know C++ and just started HTML.
That doesn't exist in pure html but it does in javascript (which can be embedded in a script tag). Javascript can be used to inject HTML into your page so through this method people often embed HTML indirectly via imported javascript.
In ES6 one of the newer versions of Javascript you can use 'import':
import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5
Example would point to a file called example.js which would export its functions using a model like.
//------ lib.js ------
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
}
Example from: http://www.2ality.com/2014/09/es6-modules-final.html
Because ES6 isn't universally used by all browsers many people use a pre-compiler which compiles modern ES6 javascript code into an older version of javascript. A common tool for this is Babel.

Grails: Asset Pipeline and GSP Templates

I've switched from using the Resources plugin to the new Asset Pipeline plugin. However, I've come across an issue that I'm not sure how to fix.
I use several templates (ie: _template.gsp) that are included via the g:render tag from other GSP files.
_template.gsp:
<%# page contentType="text/html;charset=UTF-8" %>
<asset:stylesheet src="_template.css"/>
<asset:javascript src="_template.js"/>
<div>
...
</div>
other GSP files:
...
<g:render template="/template"/>
...
In my _template.gsp file I include several assets that are required for the code in the template to work and/or look right. When I used the resources plugin to accomplish this, things worked as expected. Any files included in templates were moved to the HEAD section of the resulting GSP file. However, with the Asset Pipeline plugin, they stay in the same location where the template was included in the calling GSP file. And to make things worse, they aren't processed correctly, so they aren't loaded correctly in the resulting HTML file.
For example, in debug the resulting HTML file looks like this
...
<link rel="stylesheet" href="/assets/_template.css?compile=false"/>
<script src="/assets/_template.js?compile=false" type="text/javascript"></script>
<div>
...
</div>
...
and everything works (although the file ideally should be loaded in the HEAD section like it used to when using the Resources plugin).
In production the resulting HTML file looks like:
...
<link rel="stylesheet" href="/assets/_template.css"/>
<script src="/assets/_template.js" type="text/javascript"></script>
<div>
...
</div>
...
however, in production all other included assets (files included in the actual GSP file) have longer filenames that look like styles-6a85c6fa983d13b6f58e12b475e9d35c.css. The _template.css and _template.js files from the template isn't being converted to one of these long filenames and if I try to access the /assets/styles.css path I simply get a blank page.
I was able to solve the first part of my problem (the assets not being in the HEAD) by creating the following tag library:
class TemplateAssetsTagLib
{
// Define the namespace and encoding
static namespace = 'tasset'
static defaultEncodeAs = 'raw'
// Tag called to move the content of this tag to where the assets tag is located (usually the HTML HEAD section)
def head = { attrs, body ->
// Get any existing asset blocks
def assetBlocks = request.getAttribute('templateAssetBlocks')
if(!assetBlocks)
assetBlocks = []
// Add the body of this tag to the asset blocks list
assetBlocks << body()
request.setAttribute('templateAssetBlocks', assetBlocks)
}
// Tag called to load any content that was saved using the head tag
def assets = { attrs ->
// Get all existing asset blocks
def assetBlocks = request.getAttribute('templateAssetBlocks')
if(!assetBlocks)
return
// Output the asset blocks
assetBlocks.each { assetBlock ->
out << assetBlock
}
}
}
It's mirrored after the Asset Pipeline deferred script functionality, but more generic.
And I've been able to solve the second problem by simply renaming the assets and removing the leading underscore. For some reason assets with a leading underscore don't get compiled during WAR creation and therefore aren't accessible in production mode.

TYPO3: Write a ViewHelper in an extension with vendor namespace

I have created an extension with plugins in a vendor namespace. Everything works fine so far. All the classes start with a namespace declaration namespace \VENDOR\ExtensionName\... and typo3 autoloads them just fine.
However, the problem starts when I add a ViewHelper. I put this in the \VENDOR\ExtensionName\ViewHelpers namespace. I added the namespace in my Fluid template like so: {namespace ns=VENDOR\ExtensionName\ViewHelpers}. When I call it in the template with <ns:myViewHelper />, I just get an 'Oops ...' error message:
Could not analyse class:VENDOR\ExtensionName\ViewHelpers\MyViewHelperViewHelper maybe not loaded or no autoloader?
The same happens, when I put the ViewHelper in a \TYPO3\... namespace.
How do I correctly implement a ViewHelper in an extension with a vendor namespace?
The namespace declaration must not have a leading backslash.
Instead having \Vendor\ExtensionName\ViewHelpers; it has to be Vendor\ExtensionName\ViewHelpers;
http://www.php.net/manual/en/language.namespaces.nested.php

F# FSharp.Literate formatted code snippet does not display correctly (.css & .js?)

I'm trying to use FSharp.Literate to produce html pages. I'm working in Xamarin using Mono 4.5. I want to turn basic *.fsx scripts into html. I am using the simple script example from the documentation for tests. The script I wish to turn into html looks like this.
(**
# First-level heading
Some more documentation using `Markdown`.
*)
(*** include: final-sample ***)
(**
## Second-level heading
With some more documentation
*)
(*** define: final-sample ***)
let helloWorld() = printfn "Hello world!"
I used the built in NuGet manager to download FSharp.Formatting. It also installed Microsoft.AspNet.Razor 2 and RazorEngine
Based on the example in the documentation, I wrote the following script to turn the above example into html. I'm using the html template from the original FSharp.Formatting on github.
#I "bin/Debug/"
#r "FSharp.Literate.dll"
#r "FSharp.Markdown.dll"
#r "FSharp.CodeFormat.dll"
open System.IO
open FSharp.Literate
let source = __SOURCE_DIRECTORY__
let baseDir = Path.Combine(source, "html/")
let file = Path.Combine(baseDir, "demo.fsx")
let output = Path.Combine(baseDir, "demo-script.html")
let template = Path.Combine(baseDir, "template.html")
Literate.ProcessScriptFile(file, template, output)
The process runs and it does produce an html file. However, the F# code does not tokenize. Instead of nicely formatted code, I get the example below. Am I missing something obvious?
Edit:
Based on Tomas' comment below, I found the problem with the .css and .js files.
The template I used had href="{root}/content/style.css" /> <script src="{root}/content/tips.js"
The {root} tag was the reason it could not find the css and js files.
Changing that to href="content/style.css" /> <script src="content/tips.js" solved the problem
I think the library actually produced the correct HTML. As you can see at the end of the file, the content that should appear in the tool tips (information about the type of helloWorld and printfn) is there.
The problem is likely that the generated HTML file does not correctly reference tips.js and style.css that defines the formatting for the HTML and script to pop-up the tool tips.
These two files should be included in the NuGet package (together with the default templates), or you can find them on the project GitHub.

Vbscript classic asp custom classes

Is it possible to create customer classes in classic asp (vbscript) like you can in asp.net with c#?
Apparently it is. And here is an ASP 101 article on using them with ASP.
Yes it is possible. You can use a class file . All you need to do is write your function on a file. Suppose the name of your file is func.asp . Write all your functions or procedures in the file "func.asp" and use it <!-- #include file ="subs_functions.asp" --> Write the above line in all the pages where you want to use the functions written on "func.asp page.
If your class file is in the server(root folder) the code will be something like
<!-- #include virtual ="\YourFolderNames\myfilename.asp" -->