Code Monkey home page Code Monkey logo

ctypes.sh's Introduction

ctypes.sh

This is ctypes.sh, a foreign function interface for bash.

ctypes.sh is a bash plugin that provides a foreign function interface directly in your shell. In other words, it allows you to call routines in shared libraries from within bash.

A (very) simple example will help illustrate:

$ dlcall puts "hello, world"
hello, world

# A more complex example, use libm to calculate sin(PI/2)
$ dlopen libm.so.6
0x172ebf0
$ dlcall -r double sin double:1.57079632679489661923
double:1.000000

ctypes.sh can extend bash scripts to accomplish tasks that were previously impossible, or would require external helpers to be written.

ctypes.sh makes it possible to use GTK natively in your shell scripts, or write a high-performance http daemon.

See more examples here

prerequisites

ctypes.sh is dependent on the following libraries and programs:

  • libffi
  • bash
  • libelf (optional)
  • elfutils (optional)
  • libdwarf / libdw (optional)

Fedora

For recent Fedora, this should be enough:

sudo yum install elfutils-devel dnf-utils

Now you can use the debuginfo-install command to install debugging symbols for automatic structure support.

Ubuntu

For recent Ubuntu, this should be enough:

sudo apt install autoconf libltdl-dev libffi-dev libelf-dev elfutils libdw-dev

If you want to use automatic struct support (recommended), you should also make you have ddebs available.

install

ctypes.sh can be installed from source like this:

$ git clone https://github.com/taviso/ctypes.sh.git
$ cd ctypes.sh
$ ./autogen.sh
$ ./configure
$ make
$ [sudo] make install

By default ctypes.sh is installed into /usr/local/bin and /usr/local/lib. You can overload the prefix path by defining the PREFIX environment variable before installing.

$ PREFIX=$HOME make install

example

source ctypes.sh
puts () {
  dlcall puts "$@"
  return $?
}

puts "hello, world"

Here is what people have been saying about ctypes.sh:

  • "that's disgusting"
  • "this has got to stop"
  • "you've gone too far with this"
  • "is this a joke?"
  • "I never knew the c could stand for Cthulhu."

You can read more about ctypes.sh and see it in action on the Wiki

ctypes.sh's People

Contributors

b-t-g avatar cemeyer avatar jwerle avatar jwilk avatar linkmauve avatar rhencke avatar taviso avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.