Skip to content

Commit

Permalink
Fix C mangling for lua bindings
Browse files Browse the repository at this point in the history
This should resolve #1749.
  • Loading branch information
brndnmtthws committed Feb 25, 2024
1 parent 27d64fe commit 98087f9
Show file tree
Hide file tree
Showing 2 changed files with 373 additions and 349 deletions.
221 changes: 122 additions & 99 deletions 3rdparty/toluapp/include/tolua++.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
** enhancements, or modifications.
*/


#ifndef TOLUA_H
#define TOLUA_H

#ifndef TOLUA_API
#ifdef __cplusplus
#define TOLUA_API extern "C"
#else /* __cplusplus */
#define TOLUA_API extern
#endif /* __cplusplus */
#endif

#define TOLUA_VERSION "tolua++-1.0.92"
Expand All @@ -26,14 +29,15 @@
extern "C" {
#endif

#define tolua_pushcppstring(x,y) tolua_pushstring(x,y.c_str())
#define tolua_iscppstring tolua_isstring
#define tolua_pushcppstring(x, y) tolua_pushstring(x, y.c_str())
#define tolua_iscppstring tolua_isstring

#define tolua_iscppstringarray tolua_isstringarray
#define tolua_pushfieldcppstring(L,lo,idx,s) tolua_pushfieldstring(L, lo, idx, s.c_str())
#define tolua_pushfieldcppstring(L, lo, idx, s) \
tolua_pushfieldstring(L, lo, idx, s.c_str())

#ifndef TEMPLATE_BIND
#define TEMPLATE_BIND(p)
#define TEMPLATE_BIND(p)
#endif

#define TOLUA_TEMPLATE_BIND(p)
Expand All @@ -43,117 +47,136 @@ extern "C" {

typedef int lua_Object;

#include <lua.h>
#include <lauxlib.h>
#include <lua.h>

struct tolua_Error
{
int index;
int array;
const char* type;
struct tolua_Error {
int index;
int array;
const char* type;
};
typedef struct tolua_Error tolua_Error;

#define TOLUA_NOPEER LUA_REGISTRYINDEX /* for lua 5.1 */

TOLUA_API const char* tolua_typename (lua_State* L, int lo);
TOLUA_API void tolua_error (lua_State* L, const char* msg, tolua_Error* err);
TOLUA_API int tolua_isnoobj (lua_State* L, int lo, tolua_Error* err);
TOLUA_API int tolua_isvalue (lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isvaluenil (lua_State* L, int lo, tolua_Error* err);
TOLUA_API int tolua_isboolean (lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isnumber (lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isstring (lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_istable (lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isusertable (lua_State* L, int lo, const char* type, int def, tolua_Error* err);
TOLUA_API int tolua_isuserdata (lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isusertype (lua_State* L, int lo, const char* type, int def, tolua_Error* err);
TOLUA_API int tolua_isvaluearray
(lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_isbooleanarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_isnumberarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_isstringarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_istablearray
(lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_isuserdataarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_isusertypearray
(lua_State* L, int lo, const char* type, int dim, int def, tolua_Error* err);

TOLUA_API void tolua_open (lua_State* L);

TOLUA_API void* tolua_copy (lua_State* L, void* value, unsigned int size);
TOLUA_API int tolua_register_gc (lua_State* L, int lo);
TOLUA_API int tolua_default_collect (lua_State* tolua_S);

TOLUA_API void tolua_usertype (lua_State* L, const char* type);
TOLUA_API void tolua_beginmodule (lua_State* L, const char* name);
TOLUA_API void tolua_endmodule (lua_State* L);
TOLUA_API void tolua_module (lua_State* L, const char* name, int hasvar);
TOLUA_API void tolua_class (lua_State* L, const char* name, const char* base);
TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col);
TOLUA_API void tolua_function (lua_State* L, const char* name, lua_CFunction func);
TOLUA_API void tolua_constant (lua_State* L, const char* name, lua_Number value);
TOLUA_API void tolua_variable (lua_State* L, const char* name, lua_CFunction get, lua_CFunction set);
TOLUA_API void tolua_array (lua_State* L,const char* name, lua_CFunction get, lua_CFunction set);

/* TOLUA_API void tolua_set_call_event(lua_State* L, lua_CFunction func, char* type); */
#define TOLUA_NOPEER LUA_REGISTRYINDEX /* for lua 5.1 */

TOLUA_API const char* tolua_typename(lua_State* L, int lo);
TOLUA_API void tolua_error(lua_State* L, const char* msg, tolua_Error* err);
TOLUA_API int tolua_isnoobj(lua_State* L, int lo, tolua_Error* err);
TOLUA_API int tolua_isvalue(lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isvaluenil(lua_State* L, int lo, tolua_Error* err);
TOLUA_API int tolua_isboolean(lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isnumber(lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isstring(lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_istable(lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isusertable(lua_State* L, int lo, const char* type, int def,
tolua_Error* err);
TOLUA_API int tolua_isuserdata(lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isusertype(lua_State* L, int lo, const char* type, int def,
tolua_Error* err);
TOLUA_API int tolua_isvaluearray(lua_State* L, int lo, int dim, int def,
tolua_Error* err);
TOLUA_API int tolua_isbooleanarray(lua_State* L, int lo, int dim, int def,
tolua_Error* err);
TOLUA_API int tolua_isnumberarray(lua_State* L, int lo, int dim, int def,
tolua_Error* err);
TOLUA_API int tolua_isstringarray(lua_State* L, int lo, int dim, int def,
tolua_Error* err);
TOLUA_API int tolua_istablearray(lua_State* L, int lo, int dim, int def,
tolua_Error* err);
TOLUA_API int tolua_isuserdataarray(lua_State* L, int lo, int dim, int def,
tolua_Error* err);
TOLUA_API int tolua_isusertypearray(lua_State* L, int lo, const char* type,
int dim, int def, tolua_Error* err);

TOLUA_API void tolua_open(lua_State* L);

TOLUA_API void* tolua_copy(lua_State* L, void* value, unsigned int size);
TOLUA_API int tolua_register_gc(lua_State* L, int lo);
TOLUA_API int tolua_default_collect(lua_State* tolua_S);

TOLUA_API void tolua_usertype(lua_State* L, const char* type);
TOLUA_API void tolua_beginmodule(lua_State* L, const char* name);
TOLUA_API void tolua_endmodule(lua_State* L);
TOLUA_API void tolua_module(lua_State* L, const char* name, int hasvar);
TOLUA_API void tolua_class(lua_State* L, const char* name, const char* base);
TOLUA_API void tolua_cclass(lua_State* L, const char* lname, const char* name,
const char* base, lua_CFunction col);
TOLUA_API void tolua_function(lua_State* L, const char* name,
lua_CFunction func);
TOLUA_API void tolua_constant(lua_State* L, const char* name, lua_Number value);
TOLUA_API void tolua_variable(lua_State* L, const char* name, lua_CFunction get,
lua_CFunction set);
TOLUA_API void tolua_array(lua_State* L, const char* name, lua_CFunction get,
lua_CFunction set);

/* TOLUA_API void tolua_set_call_event(lua_State* L, lua_CFunction func, char*
* type); */
/* TOLUA_API void tolua_addbase(lua_State* L, char* name, char* base); */

TOLUA_API void tolua_pushvalue (lua_State* L, int lo);
TOLUA_API void tolua_pushboolean (lua_State* L, int value);
TOLUA_API void tolua_pushnumber (lua_State* L, lua_Number value);
TOLUA_API void tolua_pushstring (lua_State* L, const char* value);
TOLUA_API void tolua_pushuserdata (lua_State* L, void* value);
TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type);
TOLUA_API void tolua_pushusertype_and_takeownership(lua_State* L, void* value, const char* type);
TOLUA_API void tolua_pushfieldvalue (lua_State* L, int lo, int index, int v);
TOLUA_API void tolua_pushfieldboolean (lua_State* L, int lo, int index, int v);
TOLUA_API void tolua_pushfieldnumber (lua_State* L, int lo, int index, lua_Number v);
TOLUA_API void tolua_pushfieldstring (lua_State* L, int lo, int index, const char* v);
TOLUA_API void tolua_pushfielduserdata (lua_State* L, int lo, int index, void* v);
TOLUA_API void tolua_pushfieldusertype (lua_State* L, int lo, int index, void* v, const char* type);
TOLUA_API void tolua_pushfieldusertype_and_takeownership (lua_State* L, int lo, int index, void* v, const char* type);

TOLUA_API lua_Number tolua_tonumber (lua_State* L, int narg, lua_Number def);
TOLUA_API const char* tolua_tostring (lua_State* L, int narg, const char* def);
TOLUA_API void* tolua_touserdata (lua_State* L, int narg, void* def);
TOLUA_API void* tolua_tousertype (lua_State* L, int narg, void* def);
TOLUA_API int tolua_tovalue (lua_State* L, int narg, int def);
TOLUA_API int tolua_toboolean (lua_State* L, int narg, int def);
TOLUA_API lua_Number tolua_tofieldnumber (lua_State* L, int lo, int index, lua_Number def);
TOLUA_API const char* tolua_tofieldstring (lua_State* L, int lo, int index, const char* def);
TOLUA_API void* tolua_tofielduserdata (lua_State* L, int lo, int index, void* def);
TOLUA_API void* tolua_tofieldusertype (lua_State* L, int lo, int index, void* def);
TOLUA_API int tolua_tofieldvalue (lua_State* L, int lo, int index, int def);
TOLUA_API int tolua_getfieldboolean (lua_State* L, int lo, int index, int def);

TOLUA_API void tolua_dobuffer(lua_State* L, char* B, unsigned int size, const char* name);

TOLUA_API int class_gc_event (lua_State* L);
TOLUA_API void tolua_pushvalue(lua_State* L, int lo);
TOLUA_API void tolua_pushboolean(lua_State* L, int value);
TOLUA_API void tolua_pushnumber(lua_State* L, lua_Number value);
TOLUA_API void tolua_pushstring(lua_State* L, const char* value);
TOLUA_API void tolua_pushuserdata(lua_State* L, void* value);
TOLUA_API void tolua_pushusertype(lua_State* L, void* value, const char* type);
TOLUA_API void tolua_pushusertype_and_takeownership(lua_State* L, void* value,
const char* type);
TOLUA_API void tolua_pushfieldvalue(lua_State* L, int lo, int index, int v);
TOLUA_API void tolua_pushfieldboolean(lua_State* L, int lo, int index, int v);
TOLUA_API void tolua_pushfieldnumber(lua_State* L, int lo, int index,
lua_Number v);
TOLUA_API void tolua_pushfieldstring(lua_State* L, int lo, int index,
const char* v);
TOLUA_API void tolua_pushfielduserdata(lua_State* L, int lo, int index,
void* v);
TOLUA_API void tolua_pushfieldusertype(lua_State* L, int lo, int index, void* v,
const char* type);
TOLUA_API void tolua_pushfieldusertype_and_takeownership(lua_State* L, int lo,
int index, void* v,
const char* type);

TOLUA_API lua_Number tolua_tonumber(lua_State* L, int narg, lua_Number def);
TOLUA_API const char* tolua_tostring(lua_State* L, int narg, const char* def);
TOLUA_API void* tolua_touserdata(lua_State* L, int narg, void* def);
TOLUA_API void* tolua_tousertype(lua_State* L, int narg, void* def);
TOLUA_API int tolua_tovalue(lua_State* L, int narg, int def);
TOLUA_API int tolua_toboolean(lua_State* L, int narg, int def);
TOLUA_API lua_Number tolua_tofieldnumber(lua_State* L, int lo, int index,
lua_Number def);
TOLUA_API const char* tolua_tofieldstring(lua_State* L, int lo, int index,
const char* def);
TOLUA_API void* tolua_tofielduserdata(lua_State* L, int lo, int index,
void* def);
TOLUA_API void* tolua_tofieldusertype(lua_State* L, int lo, int index,
void* def);
TOLUA_API int tolua_tofieldvalue(lua_State* L, int lo, int index, int def);
TOLUA_API int tolua_getfieldboolean(lua_State* L, int lo, int index, int def);

TOLUA_API void tolua_dobuffer(lua_State* L, char* B, unsigned int size,
const char* name);

TOLUA_API int class_gc_event(lua_State* L);

#ifdef __cplusplus
static inline const char* tolua_tocppstring (lua_State* L, int narg, const char* def) {

const char* s = tolua_tostring(L, narg, def);
return s?s:"";
static inline const char* tolua_tocppstring(lua_State* L, int narg,
const char* def) {
const char* s = tolua_tostring(L, narg, def);
return s ? s : "";
}

static inline const char* tolua_tofieldcppstring (lua_State* L, int lo, int index, const char* def) {

const char* s = tolua_tofieldstring(L, lo, index, def);
return s?s:"";
static inline const char* tolua_tofieldcppstring(lua_State* L, int lo,
int index, const char* def) {
const char* s = tolua_tofieldstring(L, lo, index, def);
return s ? s : "";
}

#else
#define tolua_tocppstring tolua_tostring
#define tolua_tofieldcppstring tolua_tofieldstring
#endif

TOLUA_API int tolua_fast_isa(lua_State *L, int mt_indexa, int mt_indexb, int super_index);
TOLUA_API int tolua_fast_isa(lua_State* L, int mt_indexa, int mt_indexb,
int super_index);

#ifndef Mtolua_new
#define Mtolua_new(EXP) new EXP
Expand All @@ -168,7 +191,7 @@ TOLUA_API int tolua_fast_isa(lua_State *L, int mt_indexa, int mt_indexb, int sup
#endif

#ifndef Mtolua_delete_dim
#define Mtolua_delete_dim(EXP) delete [] EXP
#define Mtolua_delete_dim(EXP) delete[] EXP
#endif

#ifndef tolua_outside
Expand Down
Loading

0 comments on commit 98087f9

Please sign in to comment.