mirror of
https://codeberg.org/scip/rpnc.git
synced 2025-12-17 04:21:01 +01:00
Compare commits
3 Commits
v2.0.12
...
internal/a
| Author | SHA1 | Date | |
|---|---|---|---|
| a7fa0def04 | |||
| c9815e8ba3 | |||
| d0376a63e3 |
34
calc.go
34
calc.go
@@ -261,7 +261,7 @@ func (c *Calc) Eval(line string) {
|
||||
continue
|
||||
}
|
||||
|
||||
if exists(c.Funcalls, item) {
|
||||
if _, ok := c.Funcalls[item]; ok {
|
||||
if err := c.DoFuncall(item); err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
@@ -270,18 +270,20 @@ func (c *Calc) Eval(line string) {
|
||||
continue
|
||||
}
|
||||
|
||||
if exists(c.BatchFuncalls, item) {
|
||||
if !c.batch {
|
||||
if c.batch {
|
||||
if _, ok := c.BatchFuncalls[item]; ok {
|
||||
if err := c.DoFuncall(item); err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
c.Result()
|
||||
}
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
if _, ok := c.BatchFuncalls[item]; ok {
|
||||
fmt.Println("only supported in batch mode")
|
||||
continue
|
||||
}
|
||||
|
||||
if err := c.DoFuncall(item); err != nil {
|
||||
fmt.Println(err)
|
||||
} else {
|
||||
c.Result()
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if contains(c.LuaFunctions, item) {
|
||||
@@ -302,22 +304,22 @@ func (c *Calc) Eval(line string) {
|
||||
}
|
||||
|
||||
// internal commands
|
||||
if exists(c.Commands, item) {
|
||||
if _, ok := c.Commands[item]; ok {
|
||||
c.Commands[item].Func(c)
|
||||
continue
|
||||
}
|
||||
|
||||
if exists(c.ShowCommands, item) {
|
||||
if _, ok := c.ShowCommands[item]; ok {
|
||||
c.ShowCommands[item].Func(c)
|
||||
continue
|
||||
}
|
||||
|
||||
if exists(c.StackCommands, item) {
|
||||
if _, ok := c.StackCommands[item]; ok {
|
||||
c.StackCommands[item].Func(c)
|
||||
continue
|
||||
}
|
||||
|
||||
if exists(c.SettingsCommands, item) {
|
||||
if _, ok := c.SettingsCommands[item]; ok {
|
||||
c.SettingsCommands[item].Func(c)
|
||||
continue
|
||||
}
|
||||
@@ -505,7 +507,7 @@ func (c *Calc) PutVar(name string) {
|
||||
}
|
||||
|
||||
func (c *Calc) GetVar(name string) {
|
||||
if exists(c.Vars, name) {
|
||||
if _, ok := c.Vars[name]; ok {
|
||||
c.Debug(fmt.Sprintf("retrieve %.2f from %s", c.Vars[name], name))
|
||||
c.stack.Backup()
|
||||
c.stack.Push(c.Vars[name])
|
||||
@@ -518,10 +520,8 @@ func sortcommands(hash Commands) []string {
|
||||
keys := make([]string, 0, len(hash))
|
||||
|
||||
for key := range hash {
|
||||
if len(key) > 1 {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Strings(keys)
|
||||
|
||||
|
||||
2
main.go
2
main.go
@@ -30,7 +30,7 @@ import (
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
const VERSION string = "2.0.12"
|
||||
const VERSION string = "2.0.11"
|
||||
|
||||
const Usage string = `This is rpn, a reverse polish notation calculator cli.
|
||||
|
||||
|
||||
16
util.go
16
util.go
@@ -23,24 +23,16 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// find an item in a list, generic variant
|
||||
func contains[E comparable](s []E, v E) bool {
|
||||
for _, vs := range s {
|
||||
if v == vs {
|
||||
// find an item in a list
|
||||
func contains(s []string, e string) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// look if a key in a map exists, generic variant
|
||||
func exists[K comparable, V any](m map[K]V, v K) bool {
|
||||
if _, ok := m[v]; ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func const2num(name string) float64 {
|
||||
switch name {
|
||||
case "Pi":
|
||||
|
||||
Reference in New Issue
Block a user