forked from node-ffi/node-ffi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
If you've already got node installed, this can be used: | ||
|
||
$ node-waf build | ||
... | ||
$ node factorial.js 35 | ||
Your output: 6399018521010896896 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <stdint.h> | ||
|
||
uint64_t factorial(int max) { | ||
int i = max; | ||
uint64_t result = 1; | ||
|
||
while (i >= 2) | ||
result *= i--; | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var FFI = require("../../lib/ffi"); | ||
|
||
var libfactorial = new FFI.Library("libfactorial", { | ||
"factorial": [ "long", [ "uint64" ] ] | ||
}); | ||
|
||
if (process.argv.length < 3) { | ||
console.log("Arguments: " + process.argv[0] + " " + process.argv[1] + " <max>"); | ||
process.exit(); | ||
} | ||
|
||
var output = libfactorial.factorial(parseInt(process.argv[2])) | ||
|
||
console.log("Your output: " + output); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Options | ||
from os import unlink, symlink, popen | ||
from os.path import exists | ||
from logging import fatal | ||
|
||
srcdir = '.' | ||
blddir = 'build' | ||
|
||
def set_options(opt): | ||
opt.tool_options('compiler_cc') | ||
|
||
def configure(conf): | ||
conf.check_tool('compiler_cc') | ||
|
||
def build(bld): | ||
obj = bld.new_task_gen('cc', 'shlib') | ||
obj.target = 'factorial' | ||
obj.source = 'factorial.c' | ||
|
||
def shutdown(): | ||
if exists("build/default/libfactorial.dylib") and not exists("libfactorial.dylib"): | ||
symlink("build/default/libfactorial.dylib", "libfactorial.dylib") | ||
if exists("build/default/libfactorial.so") and not exists("libfactorial.so"): | ||
symlink("build/default/libfactorial.so", "libfactorial.so") |