Fix Lua examples for running under Lua 5.2
Includes cherry picking parts of
ce2760f77e
This commit is contained in:
parent
0ed98c0606
commit
bf313809ae
6 changed files with 26 additions and 11 deletions
|
|
@ -36,6 +36,10 @@ extern "C" int luaopen_example2(lua_State*L);
|
||||||
#define DEBUG2(X,Y) {printf(X,Y);fflush(stdout);}
|
#define DEBUG2(X,Y) {printf(X,Y);fflush(stdout);}
|
||||||
#define DEBUG3(X,Y,Z) {printf(X,Y,Z);fflush(stdout);}
|
#define DEBUG3(X,Y,Z) {printf(X,Y,Z);fflush(stdout);}
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM > 501
|
||||||
|
#define lua_open luaL_newstate
|
||||||
|
#endif
|
||||||
|
|
||||||
void testModule(lua_State *L)
|
void testModule(lua_State *L)
|
||||||
{
|
{
|
||||||
swig_type_info *pTypeInfo=0,*pTypeInfo2=0;
|
swig_type_info *pTypeInfo=0,*pTypeInfo2=0;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ TARGET = embed
|
||||||
SRCS = example.c
|
SRCS = example.c
|
||||||
INTERFACE = example.i
|
INTERFACE = example.i
|
||||||
LUA_INTERP = embed.c
|
LUA_INTERP = embed.c
|
||||||
|
LIBS = -lm
|
||||||
|
|
||||||
# this is a little different to normal as we have our own special interpreter
|
# this is a little different to normal as we have our own special interpreter
|
||||||
# which we want to static link
|
# which we want to static link
|
||||||
|
|
@ -12,7 +13,7 @@ check: build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile lua_clean
|
$(MAKE) -f $(TOP)/Makefile lua_clean
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM > 501
|
||||||
|
#define lua_open luaL_newstate
|
||||||
|
#endif
|
||||||
|
|
||||||
/* the SWIG wrappered library */
|
/* the SWIG wrappered library */
|
||||||
extern int luaopen_example(lua_State*L);
|
extern int luaopen_example(lua_State*L);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ TARGET = embed2
|
||||||
SRCS = example.c
|
SRCS = example.c
|
||||||
INTERFACE = example.i
|
INTERFACE = example.i
|
||||||
LUA_INTERP = embed2.c
|
LUA_INTERP = embed2.c
|
||||||
|
LIBS = -lm
|
||||||
|
|
||||||
# this is a little different to normal as we have our own special interpreter
|
# this is a little different to normal as we have our own special interpreter
|
||||||
# which we want to static link
|
# which we want to static link
|
||||||
|
|
@ -12,7 +13,7 @@ check: build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' LIBS='$(LIBS)' INTERFACE='example.i' LUA_INTERP='$(LUA_INTERP)' lua_static
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile lua_clean
|
$(MAKE) -f $(TOP)/Makefile lua_clean
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,9 @@ We will be using the luaL_dostring()/lua_dostring() function to call into lua
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM > 501
|
||||||
|
#define lua_open luaL_newstate
|
||||||
|
#endif
|
||||||
|
|
||||||
/* the SWIG wrappered library */
|
/* the SWIG wrappered library */
|
||||||
extern int luaopen_example(lua_State*L);
|
extern int luaopen_example(lua_State*L);
|
||||||
|
|
@ -46,8 +49,7 @@ int call_add(lua_State *L,int a,int b,int* res) {
|
||||||
push a, push b, call 'add' check & return res
|
push a, push b, call 'add' check & return res
|
||||||
*/
|
*/
|
||||||
top=lua_gettop(L); /* for later */
|
top=lua_gettop(L); /* for later */
|
||||||
lua_pushstring(L, "add"); /* function name */
|
lua_getglobal(L, "add"); /* function to be called */
|
||||||
lua_gettable(L, LUA_GLOBALSINDEX); /* function to be called */
|
|
||||||
if (!lua_isfunction(L,-1)) {
|
if (!lua_isfunction(L,-1)) {
|
||||||
printf("[C] error: cannot find function 'add'\n");
|
printf("[C] error: cannot find function 'add'\n");
|
||||||
lua_settop(L,top); // reset
|
lua_settop(L,top); // reset
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@ extern "C" {
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LUA_VERSION_NUM > 501
|
||||||
|
#define lua_open luaL_newstate
|
||||||
|
#endif
|
||||||
|
|
||||||
/* The SWIG external runtime is generated by using.
|
/* The SWIG external runtime is generated by using.
|
||||||
swig -lua -externalruntime swigluarun.h
|
swig -lua -externalruntime swigluarun.h
|
||||||
It contains useful function used by SWIG in its wrappering
|
It contains useful function used by SWIG in its wrappering
|
||||||
|
|
@ -65,8 +69,7 @@ int call_onEvent(lua_State *L, Event e) {
|
||||||
push a, push b, call 'add' check & return res
|
push a, push b, call 'add' check & return res
|
||||||
*/
|
*/
|
||||||
top = lua_gettop(L); /* for later */
|
top = lua_gettop(L); /* for later */
|
||||||
lua_pushstring(L, "onEvent"); /* function name */
|
lua_getglobal(L, "onEvent"); /* function to be called */
|
||||||
lua_gettable(L, LUA_GLOBALSINDEX); /* function to be called */
|
|
||||||
if (!lua_isfunction(L, -1)) {
|
if (!lua_isfunction(L, -1)) {
|
||||||
printf("[C++] error: cannot find function 'OnEvent'\n");
|
printf("[C++] error: cannot find function 'OnEvent'\n");
|
||||||
lua_settop(L, top); // reset
|
lua_settop(L, top); // reset
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue