Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent compile errors with certain versions of cgo #6

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 48 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

11 changes: 4 additions & 7 deletions README
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.



4 changes: 2 additions & 2 deletions lua51/golua.c → golua.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 4 additions & 9 deletions lua51/lua.go → lua.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
}
Expand Down
54 changes: 0 additions & 54 deletions lua51/Makefile

This file was deleted.