Perl: how can I put all my inline C code into a separate file? -


this problem simple can feel rtfm's coming. however, i've been looking @ docs (inline, inline-c, inline-c-cookbook ) morning , can't figure out how solve problem.

i want use inline c, don't want have c code in same file perl code.

(emacs doesn't having 2 languages in 1 file. in principle matter of convenience, in practice i'm having edit c in 1 file copy-paste perl script.)

here working perl:

#!/usr/bin/perl  use inline c => data; use strict; use warnings; use list::util qw(sum); use feature qw(say);  @array = (1..10); "native perl: ", sum(@array), ", inline c: ", sum1(\@array);  __end__ __c__  double sum1(av* array) {   int i;   double sum = 0.0;   (i=0; i<=av_len(array); i++) {     sv** elem = av_fetch(array, i, 0);     if (elem != null)       sum += svnv(*elem);   }   return sum; } 

(thanks mobrule getting me far.)

i want move of c code (or as possible) separate header file.

what can put sum1 header, , this:

# same perl above except sum2 instead of sum1 __end__ __c__ #include "sum.h"  double sum2(av* array) {     sum1(array); } 

this enough no longer have edit c in perl-mode, wonder if there isn't more elegant solution problem?

you can put c code in separate file , use inline::bind load @ runtime

use inline; use file::slurp;  $data = read_file('source.c'); inline->bind(c => $data); 

or loading source code in begin {} block bind @ compile time

my $data; use file::slurp; begin {     $data = read_file('source.c'); } use inline c => $data; 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -