Skip to content

Commit

Permalink
Fix lua binding compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: owentou <[email protected]>
  • Loading branch information
owent committed Aug 12, 2022
1 parent 0c65313 commit acf64fb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
12 changes: 12 additions & 0 deletions upb/bindings/lua/def.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,11 @@ const upb_FileDef* lupb_FileDef_check(lua_State* L, int narg) {

static int lupb_FileDef_Dependency(lua_State* L) {
const upb_FileDef* f = lupb_FileDef_check(L, 1);
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
int index = luaL_checkinteger(L, 2);
#else
int index = luaL_checkint(L, 2);
#endif
const upb_FileDef* dep = upb_FileDef_Dependency(f, index);
lupb_wrapper_pushwrapper(L, 1, dep, LUPB_FILEDEF);
return 1;
Expand All @@ -631,7 +635,11 @@ static int lupb_FileDef_DependencyCount(lua_State* L) {

static int lupb_FileDef_enum(lua_State* L) {
const upb_FileDef* f = lupb_FileDef_check(L, 1);
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
int index = luaL_checkinteger(L, 2);
#else
int index = luaL_checkint(L, 2);
#endif
const upb_EnumDef* e = upb_FileDef_TopLevelEnum(f, index);
lupb_wrapper_pushwrapper(L, 1, e, LUPB_ENUMDEF);
return 1;
Expand All @@ -645,7 +653,11 @@ static int lupb_FileDef_enumcount(lua_State* L) {

static int lupb_FileDef_msg(lua_State* L) {
const upb_FileDef* f = lupb_FileDef_check(L, 1);
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
int index = luaL_checkinteger(L, 2);
#else
int index = luaL_checkint(L, 2);
#endif
const upb_MessageDef* m = upb_FileDef_TopLevelMessage(f, index);
lupb_wrapper_pushwrapper(L, 1, m, LUPB_MSGDEF);
return 1;
Expand Down
2 changes: 2 additions & 0 deletions upb/bindings/lua/upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@
/* Lua compatibility code *****************************************************/

/* Shims for upcoming Lua 5.3 functionality. */
#if (!defined(LUA_VERSION_NUM)) || LUA_VERSION_NUM < 503
static bool lua_isinteger(lua_State* L, int argn) {
LUPB_UNUSED(L);
LUPB_UNUSED(argn);
return false;
}
#endif

/* Utility functions **********************************************************/

Expand Down
12 changes: 6 additions & 6 deletions upb/bindings/lua/upbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/plugin.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "google/protobuf/compiler/code_generator.h"
#include "google/protobuf/compiler/plugin.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h"

namespace protoc = ::google::protobuf::compiler;
namespace protobuf = ::google::protobuf;
Expand Down Expand Up @@ -79,7 +79,7 @@ static void PrintString(int max_cols, absl::string_view* str,
} else if (ch == '\'') {
printer->PrintRaw("\\'");
max_cols--;
} else if (isprint(ch)) {
} else if (isprint(static_cast<int>(static_cast<unsigned char>(ch)))) {
printer->WriteRaw(&ch, 1);
max_cols--;
} else {
Expand Down

0 comments on commit acf64fb

Please sign in to comment.