From d65e46a8ac20ffb76c5bd3c9e1d44ebe33fe9b2d Mon Sep 17 00:00:00 2001 From: Gabriel Silk Date: Wed, 12 Oct 2011 12:56:17 -0700 Subject: [PATCH 1/8] Fix export names in lua.go to avoid cgo compile errors --- lua51/lua.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua51/lua.go b/lua51/lua.go index 9cb9e647..306fa36c 100644 --- a/lua51/lua.go +++ b/lua51/lua.go @@ -105,19 +105,19 @@ func golua_gchook(L interface{}, id uint) int { return 0; } -//export golua_callpanicfunction +//export callpanicfunction func callpanicfunction(L interface{}, id uint) int { L1 := L.(*State); f := L1.registry[id].(GoFunction); return f(L1); } -//export golua_idtointerface +//export idtointerface func idtointerface(id uint) interface{} { return id; } -//export golua_cfunctiontointerface +//export cfunctiontointerface func cfunctiontointerface(f *uintptr) interface{} { return f; } @@ -156,7 +156,7 @@ func (L *State) NewUserdata(size uintptr) unsafe.Pointer { type Alloc func(ptr unsafe.Pointer, osize uint, nsize uint) unsafe.Pointer; -//export golua_callallocf +//export callAllocf func callAllocf(fp uintptr, ptr uintptr, osize uint, nsize uint) uintptr { return uintptr((*((*Alloc)(unsafe.Pointer(fp))))(unsafe.Pointer(ptr),osize,nsize)); From b200de3f08094a5451ceee9b0f4b939871915d30 Mon Sep 17 00:00:00 2001 From: Gabriel Silk Date: Wed, 12 Oct 2011 13:21:02 -0700 Subject: [PATCH 2/8] Fix compile errors --- lua51/golua.c | 6 +++--- lua51/lua.go | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lua51/golua.c b/lua51/golua.c index c8ad53e3..0eac1803 100644 --- a/lua51/golua.c +++ b/lua51/golua.c @@ -128,7 +128,7 @@ int callback_panicf(lua_State* L) } //TODO: currently setting garbage when panicf set to null -GoInterface clua_atpanic(lua_State* L, unsigned int panicf_id) +GoInterface* clua_atpanic(lua_State* L, unsigned int panicf_id) { //get old panicfid unsigned int old_id; @@ -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/lua.go b/lua51/lua.go index 306fa36c..9525a02a 100644 --- a/lua51/lua.go +++ b/lua51/lua.go @@ -105,20 +105,20 @@ func golua_gchook(L interface{}, id uint) int { return 0; } -//export callpanicfunction -func callpanicfunction(L interface{}, id uint) int { +//export golua_callpanicfunction +func golua_callpanicfunction(L interface{}, id uint) int { L1 := L.(*State); f := L1.registry[id].(GoFunction); return f(L1); } -//export idtointerface -func idtointerface(id uint) interface{} { +//export golua_idtointerface +func golua_idtointerface(id uint) interface{} { return id; } -//export cfunctiontointerface -func cfunctiontointerface(f *uintptr) interface{} { +//export golua_cfunctiontointerface +func golua_cfunctiontointerface(f *uintptr) interface{} { return f; } @@ -156,8 +156,8 @@ func (L *State) NewUserdata(size uintptr) unsafe.Pointer { type Alloc func(ptr unsafe.Pointer, osize uint, nsize uint) unsafe.Pointer; -//export callAllocf -func callAllocf(fp uintptr, ptr uintptr, +//export golua_callallocf +func golua_callallocf(fp uintptr, ptr uintptr, osize uint, nsize uint) uintptr { return uintptr((*((*Alloc)(unsafe.Pointer(fp))))(unsafe.Pointer(ptr),osize,nsize)); } From c867156199006f7c012c88f79e162d7870fc5389 Mon Sep 17 00:00:00 2001 From: Gabriel Silk Date: Wed, 12 Oct 2011 13:35:45 -0700 Subject: [PATCH 3/8] Fix incompatible type returned from clua_atpanic --- lua51/golua.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua51/golua.c b/lua51/golua.c index 0eac1803..c568d28d 100644 --- a/lua51/golua.c +++ b/lua51/golua.c @@ -128,7 +128,7 @@ int callback_panicf(lua_State* L) } //TODO: currently setting garbage when panicf set to null -GoInterface* clua_atpanic(lua_State* L, unsigned int panicf_id) +GoInterface clua_atpanic(lua_State* L, unsigned int panicf_id) { //get old panicfid unsigned int old_id; From 6eadfd571f0ec8091bbec0d811375b8d274102f1 Mon Sep 17 00:00:00 2001 From: Gabriel Silk Date: Wed, 12 Oct 2011 13:36:57 -0700 Subject: [PATCH 4/8] Remove useless Makefile --- Makefile | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index adf77e67..00000000 --- a/Makefile +++ /dev/null @@ -1,18 +0,0 @@ - -LUA51_DIR=lua51 - -all: $(LUA51_DIR)/_obj/lua51.a examples - -$(LUA51_DIR)/_obj/lua51.a: - cd $(LUA51_DIR) && make - -examples: install - cd example && make - -clean: - cd example && make clean - cd $(LUA51_DIR) && make clean - -install: - cd $(LUA51_DIR) && make install - From 5a66be068a9c60eb3f108fc596ac334271bb4bc8 Mon Sep 17 00:00:00 2001 From: Gabriel Silk Date: Wed, 12 Oct 2011 13:37:55 -0700 Subject: [PATCH 5/8] Move source files into top directory for use with goinstall --- lua51/Makefile => Makefile | 0 lua51/golua.c => golua.c | 0 lua51/golua.h => golua.h | 0 lua51/lauxlib.go => lauxlib.go | 0 lua51/lua.go => lua.go | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename lua51/Makefile => Makefile (100%) rename lua51/golua.c => golua.c (100%) rename lua51/golua.h => golua.h (100%) rename lua51/lauxlib.go => lauxlib.go (100%) rename lua51/lua.go => lua.go (100%) diff --git a/lua51/Makefile b/Makefile similarity index 100% rename from lua51/Makefile rename to Makefile diff --git a/lua51/golua.c b/golua.c similarity index 100% rename from lua51/golua.c rename to golua.c 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 100% rename from lua51/lua.go rename to lua.go From 5a14cd9af0f50a5059ff6b9430e31fb906e1cfcf Mon Sep 17 00:00:00 2001 From: Gabriel Silk Date: Wed, 12 Oct 2011 13:43:29 -0700 Subject: [PATCH 6/8] Update README --- README | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) 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. - - - From 271230435d6e1ef40860ef93242beb0b474a8dd3 Mon Sep 17 00:00:00 2001 From: Gabriel Silk Date: Wed, 12 Oct 2011 16:14:17 -0700 Subject: [PATCH 7/8] Remove useless "GC id:" Printf --- lua.go | 1 - 1 file changed, 1 deletion(-) diff --git a/lua.go b/lua.go index 9525a02a..424cabad 100644 --- a/lua.go +++ b/lua.go @@ -101,7 +101,6 @@ 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; } From a2c149a3479dcb2d81735c006ea2ca45ceb4ae94 Mon Sep 17 00:00:00 2001 From: Gabriel Silk Date: Wed, 12 Oct 2011 16:14:52 -0700 Subject: [PATCH 8/8] Remove fmt import --- lua.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua.go b/lua.go index 424cabad..3fc1038f 100644 --- a/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