- LUAMOD_API defined as 'extern "C"' in C++.
- "ANSI C" is in fact "ISO C" (comments)
- Removed option -std from makefile in testes/libs. (Easier to change
  to C++ for tests).
This commit is contained in:
Roberto I
2025-09-05 15:36:47 -03:00
parent ffbcadfb41
commit 9ea06e61f2
6 changed files with 11 additions and 5 deletions

2
lapi.c
View File

@@ -484,7 +484,7 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
/* /*
** Returns a pointer to the internal representation of an object. ** Returns a pointer to the internal representation of an object.
** Note that ANSI C does not allow the conversion of a pointer to ** Note that ISO C does not allow the conversion of a pointer to
** function to a 'void*', so the conversion here goes through ** function to a 'void*', so the conversion here goes through
** a 'size_t'. (As the returned pointer is only informative, this ** a 'size_t'. (As the returned pointer is only informative, this
** conversion should not be a problem.) ** conversion should not be a problem.)

View File

@@ -278,7 +278,7 @@ static int math_type (lua_State *L) {
*/ */
/* /*
** This code uses lots of shifts. ANSI C does not allow shifts greater ** This code uses lots of shifts. ISO C does not allow shifts greater
** than or equal to the width of the type being shifted, so some shifts ** than or equal to the width of the type being shifted, so some shifts
** are written in convoluted ways to match that restriction. For ** are written in convoluted ways to match that restriction. For
** preprocessor tests, it assumes a width of 32 bits, so the maximum ** preprocessor tests, it assumes a width of 32 bits, so the maximum

View File

@@ -34,7 +34,7 @@
#if defined(LUA_USE_WINDOWS) #if defined(LUA_USE_WINDOWS)
#define LUA_STRFTIMEOPTIONS "aAbBcdHIjmMpSUwWxXyYzZ%" \ #define LUA_STRFTIMEOPTIONS "aAbBcdHIjmMpSUwWxXyYzZ%" \
"||" "#c#x#d#H#I#j#m#M#S#U#w#W#y#Y" /* two-char options */ "||" "#c#x#d#H#I#j#m#M#S#U#w#W#y#Y" /* two-char options */
#elif defined(LUA_USE_C89) /* ANSI C 89 (only 1-char options) */ #elif defined(LUA_USE_C89) /* C89 (only 1-char options) */
#define LUA_STRFTIMEOPTIONS "aAbBcdHIjmMpSUwWxXyYZ%" #define LUA_STRFTIMEOPTIONS "aAbBcdHIjmMpSUwWxXyYZ%"
#else /* C99 specification */ #else /* C99 specification */
#define LUA_STRFTIMEOPTIONS "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%" \ #define LUA_STRFTIMEOPTIONS "aAbBcCdDeFgGhHIjmMnprRStTuUVwWxXyYzZ%" \

View File

@@ -319,7 +319,13 @@
** More often than not the libs go together with the core. ** More often than not the libs go together with the core.
*/ */
#define LUALIB_API LUA_API #define LUALIB_API LUA_API
#if defined(__cplusplus)
/* Lua uses the "C name" when calling open functions */
#define LUAMOD_API extern "C"
#else
#define LUAMOD_API LUA_API #define LUAMOD_API LUA_API
#endif
/* }================================================================== */ /* }================================================================== */

View File

@@ -1,7 +1,7 @@
#include "lua.h" #include "lua.h"
/* function from lib1.c */ /* function from lib1.c */
int lib1_export (lua_State *L); LUAMOD_API int lib1_export (lua_State *L);
LUAMOD_API int luaopen_lib11 (lua_State *L) { LUAMOD_API int luaopen_lib11 (lua_State *L) {
return lib1_export(L); return lib1_export(L);

View File

@@ -5,7 +5,7 @@ LUA_DIR = ../../
CC = gcc CC = gcc
# compilation should generate Dynamic-Link Libraries # compilation should generate Dynamic-Link Libraries
CFLAGS = -Wall -std=c99 -O2 -I$(LUA_DIR) -fPIC -shared CFLAGS = -Wall -O2 -I$(LUA_DIR) -fPIC -shared
# libraries used by the tests # libraries used by the tests
all: lib1.so lib11.so lib2.so lib21.so lib2-v2.so all: lib1.so lib11.so lib2.so lib21.so lib2-v2.so