diff --git a/Makefile b/Makefile index adf77e67..8b95a45d 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,54 @@ +# Copyright 2009 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. -LUA51_DIR=lua51 +include $(GOROOT)/src/Make.inc -all: $(LUA51_DIR)/_obj/lua51.a examples +CGO_OFILES+=golua.o -$(LUA51_DIR)/_obj/lua51.a: - cd $(LUA51_DIR) && make +ifndef LUA51_LIBNAME +LUA51_LIBNAME=lua5.1 +endif -examples: install - cd example && make +ifndef LUA51_INCLUDE_DIR +CGO_CFLAGS+=`pkg-config --cflags $(LUA51_LIBNAME)` +LUA51_INCLUDE_DIR:=$(shell pkg-config --cflags-only-I $(LUA51_LIBNAME) | sed 's/-I//' | sed 's/[ ]*$$//') +else +CGO_CFLAGS+=-I$(LUA51_INCLUDE_DIR) +endif -clean: - cd example && make clean - cd $(LUA51_DIR) && make clean +ifndef LUA51_LIB_DIR +CGO_LDFLAGS+=`pkg-config --libs $(LUA51_LIBNAME)` +else +CGO_LDFLAGS+=-L$(LUA51_LIB_DIR) -l$(LUA51_LIBNAME) +endif + +TARG=lua51 + +CGOFILES=\ + lua.go \ + lauxlib.go \ + lua_defs.go + +CLEANFILES+=lua_defs.go + +LUA_HEADERS=lua.h lauxlib.h lualib.h +LUA_HEADER_FILES:=$(patsubst %,$(LUA51_INCLUDE_DIR)/%,$(LUA_HEADERS)) +LUA_INCLUDE_DIRECTIVES:=$(patsubst %,//\#include <%>\n, $(LUA_HEADERS)) + + +include $(GOROOT)/src/Make.pkg + +%: install %.go + $(QUOTED_GOBIN)/$(GC) $*.go + $(QUOTED_GOBIN)/$(LD) -o $@ $*.$O + +golua.o: golua.c + gcc $(CGO_CFLAGS) $(_CGO_CFLAGS_$(GOARCH)) -fPIC $(CFLAGS) -c golua.c -o golua.o + +lua_defs.go: + echo "package lua51;" > lua_defs.go + echo "$(LUA_INCLUDE_DIRECTIVES)" "import \"C\"" >> lua_defs.go +# echo "import \"C\"" >> lua_defs.go + cat $(LUA_HEADER_FILES) | grep '#define LUA' | sed 's/#define/const/' | sed 's/\([A-Z_][A-Z_]*\)[\t ].*/\1 = C.\1/' >> lua_defs.go -install: - cd $(LUA51_DIR) && make install - diff --git a/README b/README index 7a68e52d..28836b40 100644 --- a/README +++ b/README @@ -1,10 +1,9 @@ Go Bindings for the lua C API -Simplest way to install: -#goinstall -u github.com/afitz/golua -#cd $GOROOT/src/pkg/github.com/afitz/golua -#make install +Install +----------------------- +goinstall -u github.com/gsilk/golua Configuration Variables @@ -21,12 +20,10 @@ LUA51_LIB_DIR default: undefined defining this overrides the pkg-config mechanism to create the LD_FLAGS + Licensing ------------------------- GoLua is released under the MIT license. Please see the LICENSE file for more information. Lua is Copyright (c) Lua.org, PUC-Rio. All rights reserved. - - - diff --git a/lua51/golua.c b/golua.c similarity index 98% rename from lua51/golua.c rename to golua.c index c8ad53e3..c568d28d 100644 --- a/lua51/golua.c +++ b/golua.c @@ -150,12 +150,12 @@ GoInterface clua_atpanic(lua_State* L, unsigned int panicf_id) //make a GoInterface with a wrapped C panicf or the original go panicf if(pf == &callback_panicf) { - return golua_idtointerface(old_id); + return golua_idtointerface(old_id); } else { //TODO: technically UB, function ptr -> non function ptr - return golua_cfunctiontointerface((int*)pf); + return golua_cfunctiontointerface((int*)pf); } } diff --git a/lua51/golua.h b/golua.h similarity index 100% rename from lua51/golua.h rename to golua.h diff --git a/lua51/lauxlib.go b/lauxlib.go similarity index 100% rename from lua51/lauxlib.go rename to lauxlib.go diff --git a/lua51/lua.go b/lua.go similarity index 98% rename from lua51/lua.go rename to lua.go index 9cb9e647..3fc1038f 100644 --- a/lua51/lua.go +++ b/lua.go @@ -5,10 +5,6 @@ package lua51 import "C" import "unsafe" -//TODO: remove -import "fmt" - - //like lua_Writer, but as p will contain capacity, not needed as separate param @@ -101,24 +97,23 @@ func golua_callgofunction(L interface{}, fid uint) int { func golua_gchook(L interface{}, id uint) int { L1 := L.(*State); L1.unregister(id); - fmt.Printf("GC id: %d\n",id); return 0; } //export golua_callpanicfunction -func callpanicfunction(L interface{}, id uint) int { +func golua_callpanicfunction(L interface{}, id uint) int { L1 := L.(*State); f := L1.registry[id].(GoFunction); return f(L1); } //export golua_idtointerface -func idtointerface(id uint) interface{} { +func golua_idtointerface(id uint) interface{} { return id; } //export golua_cfunctiontointerface -func cfunctiontointerface(f *uintptr) interface{} { +func golua_cfunctiontointerface(f *uintptr) interface{} { return f; } @@ -157,7 +152,7 @@ func (L *State) NewUserdata(size uintptr) unsafe.Pointer { type Alloc func(ptr unsafe.Pointer, osize uint, nsize uint) unsafe.Pointer; //export golua_callallocf -func callAllocf(fp uintptr, ptr uintptr, +func golua_callallocf(fp uintptr, ptr uintptr, osize uint, nsize uint) uintptr { return uintptr((*((*Alloc)(unsafe.Pointer(fp))))(unsafe.Pointer(ptr),osize,nsize)); } diff --git a/lua51/Makefile b/lua51/Makefile deleted file mode 100644 index 8b95a45d..00000000 --- a/lua51/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2009 The Go Authors. All rights reserved. -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file. - -include $(GOROOT)/src/Make.inc - -CGO_OFILES+=golua.o - -ifndef LUA51_LIBNAME -LUA51_LIBNAME=lua5.1 -endif - -ifndef LUA51_INCLUDE_DIR -CGO_CFLAGS+=`pkg-config --cflags $(LUA51_LIBNAME)` -LUA51_INCLUDE_DIR:=$(shell pkg-config --cflags-only-I $(LUA51_LIBNAME) | sed 's/-I//' | sed 's/[ ]*$$//') -else -CGO_CFLAGS+=-I$(LUA51_INCLUDE_DIR) -endif - -ifndef LUA51_LIB_DIR -CGO_LDFLAGS+=`pkg-config --libs $(LUA51_LIBNAME)` -else -CGO_LDFLAGS+=-L$(LUA51_LIB_DIR) -l$(LUA51_LIBNAME) -endif - -TARG=lua51 - -CGOFILES=\ - lua.go \ - lauxlib.go \ - lua_defs.go - -CLEANFILES+=lua_defs.go - -LUA_HEADERS=lua.h lauxlib.h lualib.h -LUA_HEADER_FILES:=$(patsubst %,$(LUA51_INCLUDE_DIR)/%,$(LUA_HEADERS)) -LUA_INCLUDE_DIRECTIVES:=$(patsubst %,//\#include <%>\n, $(LUA_HEADERS)) - - -include $(GOROOT)/src/Make.pkg - -%: install %.go - $(QUOTED_GOBIN)/$(GC) $*.go - $(QUOTED_GOBIN)/$(LD) -o $@ $*.$O - -golua.o: golua.c - gcc $(CGO_CFLAGS) $(_CGO_CFLAGS_$(GOARCH)) -fPIC $(CFLAGS) -c golua.c -o golua.o - -lua_defs.go: - echo "package lua51;" > lua_defs.go - echo "$(LUA_INCLUDE_DIRECTIVES)" "import \"C\"" >> lua_defs.go -# echo "import \"C\"" >> lua_defs.go - cat $(LUA_HEADER_FILES) | grep '#define LUA' | sed 's/#define/const/' | sed 's/\([A-Z_][A-Z_]*\)[\t ].*/\1 = C.\1/' >> lua_defs.go -