8000 GitHub - kcn1235/knife: Elegant C++11 Syntactic-Sugar for Mixed-Language Programming with Python, SQLite and Bash
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ knife Public
forked from FeifanXu/knife

Elegant C++11 Syntactic-Sugar for Mixed-Language Programming with Python, SQLite and Bash

License

Notifications You must be signed in to change notification settings

kcn1235/knife

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Knife: Mixed-Language Programming For C++11

license

You have just found Knife.

Knife is a simple, elegant, very convenient C++11 Syntactic-Sugar Lib, for mixed-language programming with Python, SQLite and Bash. It was developed with a focus on enabling simple and natural way to mixed-language programming. enjoy the advantages of those language directly.

Use Knife if you need a mixed-language programming library that:

  • Can write those languages directly without trivial work like initialization and finalization
  • Supports variable number of arguments and formatted string mechanism to avoid sprintf(...) works
  • Manipulate variables nicely, as long as variable names are same in C++ and those languages
  • Cross platform support for multithreading acceleration with a handy speed-up interface
  • Extendible to write your own language environment like Lua, R, Matlab, etc.

Documentation are still writing(sorry for my busy life).

Knife is compatible with: Python / Anaconda, Bash / Bourne shell.


Getting started: 30 seconds to Knife

$bash, $py, and $sql are singletons and functors, which restrict the instantiation of a class to one object and overload the function operator().

They can act like a function, for example void $bash(const char* cmd, ...)(but not a function), that take the command(or command's format_placeholder) as input and execute it, we call them Environments, which is extendible to other languages(we will talk about it later)

#include <knife.hpp>

int main() {

    printf("\nDemo of $bash\n");
    $bash("mkdir hello");  // execute commands in the bash environment
    $bash("ls | grep ell");// "ell" in "hello"
    $bash("rm -r hello");

    printf("\nDemo of $py\n");
    $py("msg, pi = %s, %f", "\'hello\'", 3.1415926f);   // Formatted String
    $py("print (msg)");
    $py_get(float, pi); // Same Variable Name: pi
    std::cout << pi << std::endl;

    printf("\nDemo of $sql\n");
    $sql("CREATE TABLE Foo(ID INTEGER, Msg TEXT);");
    int ID = 1;
    const char *Msg = "hello";
    $sql.insert_easily("Foo", ID, Msg); // Same Variable Name:ID, Msg
    $sql("SELECT * FROM Foo;");
    std::cout << $sql.query_result()[0][1] << std::endl;
    $sql("DROP TABLE Foo;");

    return 0;
}

the output of those code will be:

all_usage

Outputs of C++(like ptintf / std::cout) are white
Outputs of Environments are yellow
Prompts have different color corespond to the language
Commands that the Environments execute are blue

let's explain those codes:

Start Knife From $bash

$bash("mkdir hello");  // execute commands in the bash environment
$bash("ls | grep ell");// "ell" in "hello"
$bash("rm -r hello");

firstly, $bash("mkdir hello"); means the $bash singletons functors takes the string "mkdir hello" as input, then mkdir will be executed in the your Bash Environment, which makes a directory in your ./ path. then ls lists the files in the current working directory, grep the "ell" from the output of ls, rm

Advanced Operation In $py

$py("msg, pi = %s, %f", "\'hello\'", 3.1415926f);   // Formatted String
$py("print (msg)");
$py_get(float, pi); // Same Variable Name: pi
std::cout << pi << std::endl;

Manipulate Data Using $sql

$sql("CREATE TABLE Foo(ID INTEGER, Msg TEXT);");
int ID = 1;
const char *Msg = "hello";
$sql.insert_easily("Foo", ID, Msg); // Same Variable Name:ID, Msg
$sql("SELECT * FROM Foo;");
std::cout << $sql.query_result()[0][1] << std::endl;
$sql("DROP TABLE Foo;");

Installation

TODO gcc 4.9 clang x.x C++ 11

cmake


Support

TODO


Why this name, Knife?

TODO Why bash sqlite and python? lua matlab, may be supported later

this style of readme file imitates the readme of Keras, which is one of my favorite project for it's easy, friendly, handy usage ^_^


About

Elegant C++11 Syntactic-Sugar for Mixed-Language Programming with Python, SQLite and Bash

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 99.3%
  • C++ 0.7%
0