From b9ea592026de06d0db7f79a8cf11b4544259fbf0 Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 4 Sep 2014 16:39:23 +0800 Subject: [PATCH] add lua build tag maybe install golua error, and lua cannot be used --- bootstrap.sh | 2 +- dev.sh | 7 +++++++ server/cmd_script.go | 4 +++- server/cmd_script_test.go | 2 ++ server/script.go | 8 +++++++- server/script_dummy.go | 10 ++++++++++ server/script_test.go | 4 +++- tools/check_lua.go | 8 ++++++++ 8 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 server/script_dummy.go create mode 100644 tools/check_lua.go diff --git a/bootstrap.sh b/bootstrap.sh index a0eae73..ffb4c46 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -16,4 +16,4 @@ go get github.com/BurntSushi/toml go get github.com/siddontang/go-bson/bson -go get github.com/aarzilli/golua/lua \ No newline at end of file +go get github.com/siddontang/golua/lua \ No newline at end of file diff --git a/dev.sh b/dev.sh index 798ffab..7b42c8e 100644 --- a/dev.sh +++ b/dev.sh @@ -74,6 +74,13 @@ if [ -f $HYPERLEVELDB_DIR/include/hyperleveldb/c.h ]; then GO_BUILD_TAGS="$GO_BUILD_TAGS hyperleveldb" fi +#check lua +CHECK_LUA_FILE="$LEDISTOP/tools/check_lua.go" +go run $CHECK_LUA_FILE 2>/dev/null +if [ "$?" = 0 ]; then + GO_BUILD_TAGS="$GO_BUILD_TAGS lua" +fi + export CGO_CFLAGS export CGO_CXXFLAGS export CGO_LDFLAGS diff --git a/server/cmd_script.go b/server/cmd_script.go index d2a3a1c..de1844f 100644 --- a/server/cmd_script.go +++ b/server/cmd_script.go @@ -1,10 +1,12 @@ +// +build lua + package server import ( "crypto/sha1" "encoding/hex" "fmt" - "github.com/aarzilli/golua/lua" + "github.com/siddontang/golua/lua" "github.com/siddontang/ledisdb/ledis" "strconv" "strings" diff --git a/server/cmd_script_test.go b/server/cmd_script_test.go index ae3e713..017e527 100644 --- a/server/cmd_script_test.go +++ b/server/cmd_script_test.go @@ -1,3 +1,5 @@ +// +build lua + package server import ( diff --git a/server/script.go b/server/script.go index 7ecdfc9..4f230fa 100644 --- a/server/script.go +++ b/server/script.go @@ -1,9 +1,11 @@ +// +build lua + package server import ( "encoding/hex" "fmt" - "github.com/aarzilli/golua/lua" + "github.com/siddontang/golua/lua" "github.com/siddontang/ledisdb/ledis" "io" "sync" @@ -159,6 +161,10 @@ func (app *App) openScript() { l.OpenTable() l.OpenPackage() + l.OpenCJson() + l.OpenCMsgpack() + l.OpenStruct() + l.Register("error", luaErrorHandler) s.l = l diff --git a/server/script_dummy.go b/server/script_dummy.go new file mode 100644 index 0000000..f19f3b8 --- /dev/null +++ b/server/script_dummy.go @@ -0,0 +1,10 @@ +// +build !lua + +package server + +type script struct { +} + +func (app *App) openScript() {} + +func (app *App) closeScript() {} diff --git a/server/script_test.go b/server/script_test.go index 0d91231..74160d3 100644 --- a/server/script_test.go +++ b/server/script_test.go @@ -1,8 +1,10 @@ +// +build lua + package server import ( "fmt" - "github.com/aarzilli/golua/lua" + "github.com/siddontang/golua/lua" "github.com/siddontang/ledisdb/config" "testing" diff --git a/tools/check_lua.go b/tools/check_lua.go new file mode 100644 index 0000000..f0fccf8 --- /dev/null +++ b/tools/check_lua.go @@ -0,0 +1,8 @@ +package main + +import "github.com/siddontang/golua/lua" + +func main() { + L := lua.NewState() + L.Close() +}