Skip to content

Commit d97e8c4

Browse files
committed
Improve maintenance of constants (eventually they should use embed) by using textFileToGoConst
1 parent ee0c009 commit d97e8c4

File tree

8 files changed

+352
-97
lines changed

8 files changed

+352
-97
lines changed

argparse/internal/include_all_lua.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

argparse/loader.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
package argparse
22

3-
//go:generate go run internal/include_all_lua.go
4-
53
import (
6-
"encoding/base64"
7-
84
lua "github.com/yuin/gopher-lua"
95
)
106

7+
//go:generate go run github.com/logrusorgru/textFileToGoConst@latest -in argparse.lua -o lua_const.go -c lua_argparse
8+
119
// Preload adds inspect to the given Lua state's package.preload table. After it
1210
// has been preloaded, it can be loaded using require:
1311
//
14-
// local inspect = require("inspect")
12+
// local inspect = require("inspect")
1513
func Preload(L *lua.LState) {
1614
L.PreloadModule("argparse", Loader)
1715
}
1816

1917
// Loader is the module loader function.
2018
func Loader(L *lua.LState) int {
21-
code, err := base64.StdEncoding.DecodeString(lua_argparse)
22-
if err != nil {
23-
panic(err.Error())
24-
}
25-
if err := L.DoString(string(code)); err != nil {
19+
if err := L.DoString(lua_argparse); err != nil {
2620
L.RaiseError("load library 'argparse' error: %s", err.Error())
2721
}
2822
return 1

argparse/lua_const.go

Lines changed: 6 additions & 2 deletions
Large diffs are not rendered by default.

inspect/internal/include_all_lua.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

inspect/loader.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
package inspect
22

3-
//go:generate go run internal/include_all_lua.go
3+
//go:generate go run github.com/logrusorgru/textFileToGoConst@latest -in inspect.lua -o lua_const.go -c lua_inspect
44

55
import (
6-
"encoding/base64"
7-
86
lua "github.com/yuin/gopher-lua"
97
)
108

119
// Preload adds inspect to the given Lua state's package.preload table. After it
1210
// has been preloaded, it can be loaded using require:
1311
//
14-
// local inspect = require("inspect")
12+
// local inspect = require("inspect")
1513
func Preload(L *lua.LState) {
1614
L.PreloadModule("inspect", Loader)
1715
}
1816

1917
// Loader is the module loader function.
2018
func Loader(L *lua.LState) int {
21-
code, err := base64.StdEncoding.DecodeString(lua_inspect)
22-
if err != nil {
23-
panic(err.Error())
24-
}
25-
if err := L.DoString(string(code)); err != nil {
19+
if err := L.DoString(lua_inspect); err != nil {
2620
L.RaiseError("load library 'inspect' error: %s", err.Error())
2721
}
2822
return 1

inspect/lua_const.go

Lines changed: 339 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)