Skip to content

Commit 4407096

Browse files
add kotlin
1 parent 8eff2f3 commit 4407096

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

language/kotlin/kotlin.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package kotlin
2+
3+
import (
4+
"github.com/danielborowski/cb-code-runner/cmd"
5+
"path/filepath"
6+
"strings"
7+
)
8+
9+
func Run(files []string, stdin string) (string, string, error) {
10+
workDir := filepath.Dir(files[0])
11+
fname := filepath.Base(files[0])
12+
13+
stdout, stderr, err := cmd.Run(workDir, "kotlinc", fname)
14+
if err != nil {
15+
return stdout, stderr, err
16+
}
17+
18+
return cmd.RunStdin(workDir, stdin, "kotlin", className(fname))
19+
}
20+
21+
func className(fname string) string {
22+
if len(fname) < 5 {
23+
return fname
24+
}
25+
26+
ext := filepath.Ext(fname)
27+
name := fname[0 : len(fname)-len(ext)]
28+
return strings.ToUpper(string(name[0])) + name[1:] + "Kt"
29+
}

language/language.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/danielborowski/cb-code-runner/language/cpp"
1212
"github.com/danielborowski/cb-code-runner/language/csharp"
1313
"github.com/danielborowski/cb-code-runner/language/c"
14+
"github.com/danielborowski/cb-code-runner/language/kotlin"
1415
)
1516

1617
type runFn func([]string, string) (string, string, error)
@@ -26,6 +27,7 @@ var languages = map[string]runFn{
2627
"cpp": cpp.Run,
2728
"csharp": csharp.Run,
2829
"c": c.Run,
30+
"kotlin": kotlin.Run,
2931
}
3032

3133
func IsSupported(lang string) bool {

0 commit comments

Comments
 (0)