Skip to content

Commit acf64fb

Browse files
committed
Fix lua binding compatibility
Signed-off-by: owentou <[email protected]>
1 parent 0c65313 commit acf64fb

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

upb/bindings/lua/def.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,11 @@ const upb_FileDef* lupb_FileDef_check(lua_State* L, int narg) {
617617

618618
static int lupb_FileDef_Dependency(lua_State* L) {
619619
const upb_FileDef* f = lupb_FileDef_check(L, 1);
620+
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
621+
int index = luaL_checkinteger(L, 2);
622+
#else
620623
int index = luaL_checkint(L, 2);
624+
#endif
621625
const upb_FileDef* dep = upb_FileDef_Dependency(f, index);
622626
lupb_wrapper_pushwrapper(L, 1, dep, LUPB_FILEDEF);
623627
return 1;
@@ -631,7 +635,11 @@ static int lupb_FileDef_DependencyCount(lua_State* L) {
631635

632636
static int lupb_FileDef_enum(lua_State* L) {
633637
const upb_FileDef* f = lupb_FileDef_check(L, 1);
638+
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
639+
int index = luaL_checkinteger(L, 2);
640+
#else
634641
int index = luaL_checkint(L, 2);
642+
#endif
635643
const upb_EnumDef* e = upb_FileDef_TopLevelEnum(f, index);
636644
lupb_wrapper_pushwrapper(L, 1, e, LUPB_ENUMDEF);
637645
return 1;
@@ -645,7 +653,11 @@ static int lupb_FileDef_enumcount(lua_State* L) {
645653

646654
static int lupb_FileDef_msg(lua_State* L) {
647655
const upb_FileDef* f = lupb_FileDef_check(L, 1);
656+
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
657+
int index = luaL_checkinteger(L, 2);
658+
#else
648659
int index = luaL_checkint(L, 2);
660+
#endif
649661
const upb_MessageDef* m = upb_FileDef_TopLevelMessage(f, index);
650662
lupb_wrapper_pushwrapper(L, 1, m, LUPB_MSGDEF);
651663
return 1;

upb/bindings/lua/upb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@
6161
/* Lua compatibility code *****************************************************/
6262

6363
/* Shims for upcoming Lua 5.3 functionality. */
64+
#if (!defined(LUA_VERSION_NUM)) || LUA_VERSION_NUM < 503
6465
static bool lua_isinteger(lua_State* L, int argn) {
6566
LUPB_UNUSED(L);
6667
LUPB_UNUSED(argn);
6768
return false;
6869
}
70+
#endif
6971

7072
/* Utility functions **********************************************************/
7173

upb/bindings/lua/upbc.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2424
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525

26-
#include "google/protobuf/compiler/code_generator.h"
27-
#include "google/protobuf/compiler/plugin.h"
28-
#include "google/protobuf/io/printer.h"
29-
#include "google/protobuf/descriptor.pb.h"
30-
#include "google/protobuf/descriptor.h"
3126
#include "absl/strings/str_replace.h"
3227
#include "absl/strings/string_view.h"
3328
#include "absl/strings/substitute.h"
29+
#include "google/protobuf/compiler/code_generator.h"
30+
#include "google/protobuf/compiler/plugin.h"
31+
#include "google/protobuf/descriptor.h"
32+
#include "google/protobuf/descriptor.pb.h"
33+
#include "google/protobuf/io/printer.h"
3434

3535
namespace protoc = ::google::protobuf::compiler;
3636
namespace protobuf = ::google::protobuf;
@@ -79,7 +79,7 @@ static void PrintString(int max_cols, absl::string_view* str,
7979
} else if (ch == '\'') {
8080
printer->PrintRaw("\\'");
8181
max_cols--;
82-
} else if (isprint(ch)) {
82+
} else if (isprint(static_cast<int>(static_cast<unsigned char>(ch)))) {
8383
printer->WriteRaw(&ch, 1);
8484
max_cols--;
8585
} else {

0 commit comments

Comments
 (0)