library.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. // Contains a simple library definition to allow creating a Geth instance from
  17. // straight C code.
  18. package main
  19. // #ifdef __cplusplus
  20. // extern "C" {
  21. // #endif
  22. //
  23. // extern int run(const char*);
  24. //
  25. // #ifdef __cplusplus
  26. // }
  27. // #endif
  28. import "C"
  29. import (
  30. "fmt"
  31. "os"
  32. "strings"
  33. )
  34. //export doRun
  35. func doRun(args *C.char) C.int {
  36. // This is equivalent to geth.main, just modified to handle the function arg passing
  37. if err := app.Run(strings.Split("geth "+C.GoString(args), " ")); err != nil {
  38. fmt.Fprintln(os.Stderr, err)
  39. return -1
  40. }
  41. return 0
  42. }