https://github.com/bradfitz/campher
Embed Perl in Go. This works, but was a joke for a presentation. Don't use.
https://github.com/bradfitz/campher
Last synced: 3 months ago
JSON representation
Embed Perl in Go. This works, but was a joke for a presentation. Don't use.
- Host: GitHub
- URL: https://github.com/bradfitz/campher
- Owner: bradfitz
- Created: 2011-05-07T15:43:37.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2016-12-07T16:51:32.000Z (over 8 years ago)
- Last Synced: 2025-02-27T19:03:20.675Z (3 months ago)
- Language: Go
- Homepage:
- Size: 28.3 KB
- Stars: 137
- Watchers: 11
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
What do you get when you cross a Camel with a Gopher?
Campher!
Perl in Go.
Example of the awesomeness / horror:
=========
INSTALL
=========$ go get github.com/bradfitz/campher
=========
EXAMPLE
=========package main
import (
"fmt"
"strings""github.com/bradfitz/campher/perl"
)func main() {
p := perl.NewInterpreter()
p.Eval(`$foo = "bar";`)
fmt.Println("foo is:", p.EvalString("$foo"))cv := p.Eval(`sub { my ($a1, $a2, $func) = @_; $func->($a1, $a2); }`).CV()
var ret *SV
p := perl.NewInterpreter()
foo := p.Eval(`$foo = sub {
my ($op, $v1, $v2) = @_;
return "Perl says: " . $op->($v1, $v2);
};`)
concat := func(a, b string) string { return a + b }
fmt.Println("concat:", foo.CV().Call(concat, "foo", "bar"))base := 0
add := func(a, b int) int {
base++
return a + b + base
}
fmt.Println("add:", foo.CV().Call(add, 1, "40"))
fmt.Println("add:", foo.CV().Call(add, 1, "40"))
}================
EXAMPLE OUTPUT
================concat: Perl says: foobar
add: Perl says: 42
add: Perl says: 43