Convert a C function to a lambda via executable strings.
#!/usr/bin/env bash | |
read -p "Function return type: " val | |
if [ "$1" != "mini" ]; then | |
read -p "Function name: " name | |
fi | |
read -p "Function argument list: " list | |
echo "$val $name($list) {" >f.c | |
echo "Enter code:" | |
cat >>f.c | |
echo "}" >>f.c | |
gcc -Os -c f.c | |
objcopy -O binary -j .text f.o foo | |
if [ "$1" = "mini" ]; then | |
echo -n "(($val(*)($list))\"" | |
od -An -t x1 foo | tr -d '\n' | sed 's/ /\\x/g' | |
echo "\")(INSERT ARGS HERE);" | |
else | |
echo -n "$val (*$name)($list) = \"" | |
od -An -t x1 foo | tr -d '\n' | sed 's/ /\\x/g' | |
echo \"\; | |
fi | |
rm f.c f.o foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Suggest replacing references to
f.c
with/tmp/f$$.c
andfoo
with/tmp/foo$$
, etc. so you don't accidentally blow away any important files namedf.c
andfoo