summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2015-05-13 14:51:35 -0700
committerJosh Haberman <jhaberman@gmail.com>2015-05-13 14:51:44 -0700
commit51cf616dab63ba65c30cc58f0e5a61724aa4f731 (patch)
tree7a3f4be0a0ee7704c66c60d51b5985336ba21426 /upb
parent35923b43b5f9bc65db3d2f6c5a0170a0bb816ce2 (diff)
Changes to Lua module loading, and file generation.
This change has several parts: 1. Resurrected tools/upbc. The code was all there but the build was broken for open-source. Now you can type "make tools/upbc" and it will build all necessary Lua modules and create a robust shell script for running upbc. 2. Changed Lua module loading to no longer rely on OS-level .so dependencies. The net effect of this is that you now only need to set LUA_PATH and LUA_CPATH; setting LD_LIBRARY_PATH or rpaths is no longer required. Downside: this drops compatibility with Lua 5.1, since it depends on a feature that only exists in Lua >=5.2 (and LuaJIT). 3. Since upbc works again, I fixed the re-generation of the descriptor files (descriptor.upb.h, descriptor.upb.c). "make genfiles" will re-generate these as well as the JIT code generator. 4. Added a Travis test target that ensures that the checked-in generated files are not out of date. I would do this for the Ragel generated file also, but we can't count on all versions of Ragel to necessarily generate identical output. 5. Changed Makefile to no longer automatically run Ragel to regenerate the JSON parser. This is unfortuante, because it's convenient when you're developing the JSON parser. However, "git clone" sometimes skews the timestamps a little bit so that "make" thinks it needs to regenerate these files for a fresh "git clone." This would normally be harmless, but if the user doesn't have Ragel installed, it makes the build fail completely. So now you have to explicitly regenerate the Ragel output. If you want to you can uncomment the auto-generation during development.
Diffstat (limited to 'upb')
-rw-r--r--upb/bindings/lua/upb.c17
-rw-r--r--upb/bindings/lua/upb.lua248
-rw-r--r--upb/bindings/lua/upb/pb.c6
-rw-r--r--upb/bindings/lua/upb/pb.lua11
-rw-r--r--upb/bindings/lua/upb/table.c (renamed from upb/bindings/lua/table.c)2
-rw-r--r--upb/bindings/lua/upb/table.lua11
6 files changed, 156 insertions, 139 deletions
diff --git a/upb/bindings/lua/upb.c b/upb/bindings/lua/upb.c
index b35af24..aebf9f7 100644
--- a/upb/bindings/lua/upb.c
+++ b/upb/bindings/lua/upb.c
@@ -33,10 +33,6 @@
#include "upb/pb/glue.h"
#include "upb/shim/shim.h"
-static const char upb_lua[] = {
-#include "upb/bindings/lua/upb.lua.h"
-};
-
// Lua metatable types.
#define LUPB_MSG "lupb.msg"
#define LUPB_ARRAY "lupb.array"
@@ -1771,9 +1767,9 @@ static void lupb_setfieldi(lua_State *L, const char *field, int i) {
lua_setfield(L, -2, field);
}
-int luaopen_upb(lua_State *L) {
+int luaopen_upb_c(lua_State *L) {
static char module_key;
- if (lupb_openlib(L, &module_key, "upb", lupb_toplevel_m)) {
+ if (lupb_openlib(L, &module_key, "upb_c", lupb_toplevel_m)) {
return 1;
}
@@ -1858,14 +1854,5 @@ int luaopen_upb(lua_State *L) {
lupb_setfieldi(L, "HANDLER_STARTSEQ", UPB_HANDLER_STARTSEQ);
lupb_setfieldi(L, "HANDLER_ENDSEQ", UPB_HANDLER_ENDSEQ);
- // Call the chunk that will define the extra functions on upb, passing our
- // package dictionary as the argument.
- if (luaL_loadbuffer(L, upb_lua, sizeof(upb_lua), "upb.lua") ||
- lua_pcall(L, 0, LUA_MULTRET, 0)) {
- lua_error(L);
- }
- lua_pushvalue(L, -2);
- lua_call(L, 1, 0);
-
return 1; // Return package table.
}
diff --git a/upb/bindings/lua/upb.lua b/upb/bindings/lua/upb.lua
index bda9dfe..4090b37 100644
--- a/upb/bindings/lua/upb.lua
+++ b/upb/bindings/lua/upb.lua
@@ -1,146 +1,156 @@
+--[[--------------------------------------------------------------------
+
+ upb - a minimalist implementation of protocol buffers.
+
+ Copyright (c) 2009 Google Inc. See LICENSE for details.
+ Author: Josh Haberman <jhaberman@gmail.com>
+
+--------------------------------------------------------------------]]--
+
+-- Before calling require on "upb_c", we need to load the same library
+-- as RTLD_GLOBAL, for the benefit of other C extensions that depend on
+-- C functions in the core.
--
--- upb - a minimalist implementation of protocol buffers.
---
--- Copyright (c) 2009 Google Inc. See LICENSE for details.
--- Author: Josh Haberman <jhaberman@gmail.com>
+-- This has to happen *before* the require call, because if the module
+-- is loaded RTLD_LOCAL first, a subsequent load as RTLD_GLOBAL won't
+-- have the proper effect, at least on some platforms.
+package.loadlib(package.searchpath("upb_c", package.cpath), "*")
+
+local upb = require("upb_c")
+
+-- A convenience function for building/linking/freezing defs
+-- while maintaining their original order.
--
--- Pure-Lua support functions that are part of the "upb" module.
--- This file is embedded and packaged into the "upb" C module binary -- it
--- should not be installed or used directly!
-
-return function(upb)
- -- A convenience function for building/linking/freezing defs
- -- while maintaining their original order.
- --
- -- Sample usage:
- -- local m1, m2 = upb.build_defs{
- -- upb.MessageDef{full_name = "M1", fields = {
- -- upb.FieldDef{
- -- name = "m2",
- -- number = 1,
- -- type = upb.TYPE_MESSAGE,
- -- subdef_name = ".M2"
- -- },
- -- }
- -- },
- -- upb.MessageDef{full_name = "M2"}
- -- }
- upb.build_defs = function(defs)
- upb.SymbolTable(defs)
- -- Lua 5.2 puts unpack in the table library.
- return (unpack or table.unpack)(defs)
- end
+-- Sample usage:
+-- local m1, m2 = upb.build_defs{
+-- upb.MessageDef{full_name = "M1", fields = {
+-- upb.FieldDef{
+-- name = "m2",
+-- number = 1,
+-- type = upb.TYPE_MESSAGE,
+-- subdef_name = ".M2"
+-- },
+-- }
+-- },
+-- upb.MessageDef{full_name = "M2"}
+-- }
+upb.build_defs = function(defs)
+ upb.SymbolTable(defs)
+ -- Lua 5.2 puts unpack in the table library.
+ return (unpack or table.unpack)(defs)
+end
- local ipairs_iter = function(array, last_index)
- local next_index = last_index + 1
- if next_index > #array then
- return nil
- end
- return next_index, array[next_index]
+local ipairs_iter = function(array, last_index)
+ local next_index = last_index + 1
+ if next_index > #array then
+ return nil
end
+ return next_index, array[next_index]
+end
- -- For iterating over the indexes and values of a upb.Array.
- --
- -- for i, val in upb.ipairs(array) do
- -- -- ...
- -- end
- upb.ipairs = function(array)
- return ipairs_iter, array, 0
- end
+-- For iterating over the indexes and values of a upb.Array.
+--
+-- for i, val in upb.ipairs(array) do
+-- -- ...
+-- end
+upb.ipairs = function(array)
+ return ipairs_iter, array, 0
+end
- local set_named = function(obj, init)
- for k, v in pairs(init) do
- local func = obj["set_" .. k]
- if not func then
- error("Cannot set member: " .. k)
- end
- func(obj, v)
+local set_named = function(obj, init)
+ for k, v in pairs(init) do
+ local func = obj["set_" .. k]
+ if not func then
+ error("Cannot set member: " .. k)
end
+ func(obj, v)
end
+end
+
+-- Capture references to the functions we're wrapping.
+local RealFieldDef = upb.FieldDef
+local RealEnumDef = upb.EnumDef
+local RealMessageDef = upb.MessageDef
+local RealSymbolTable = upb.SymbolTable
- -- Capture references to the functions we're wrapping.
- local RealFieldDef = upb.FieldDef
- local RealEnumDef = upb.EnumDef
- local RealMessageDef = upb.MessageDef
- local RealSymbolTable = upb.SymbolTable
-
- -- FieldDef constructor; a wrapper around the real constructor that can
- -- set initial properties.
- --
- -- User can specify initialization values like so:
- -- upb.FieldDef{label=upb.LABEL_REQUIRED, name="my_field", number=5,
- -- type=upb.TYPE_INT32, default_value=12, type_name="Foo"}
- upb.FieldDef = function(init)
- local f = RealFieldDef()
-
- if init then
- -- Other members are often dependent on type, so set that first.
- if init.type then
- f:set_type(init.type)
- init.type = nil
- end
-
- set_named(f, init)
+-- FieldDef constructor; a wrapper around the real constructor that can
+-- set initial properties.
+--
+-- User can specify initialization values like so:
+-- upb.FieldDef{label=upb.LABEL_REQUIRED, name="my_field", number=5,
+-- type=upb.TYPE_INT32, default_value=12, type_name="Foo"}
+upb.FieldDef = function(init)
+ local f = RealFieldDef()
+
+ if init then
+ -- Other members are often dependent on type, so set that first.
+ if init.type then
+ f:set_type(init.type)
+ init.type = nil
end
- return f
+ set_named(f, init)
end
+ return f
+end
- -- MessageDef constructor; a wrapper around the real constructor that can
- -- set initial properties.
- --
- -- User can specify initialization values like so:
- -- upb.MessageDef{full_name="MyMessage", extstart=8000, fields={...}}
- upb.MessageDef = function(init)
- local m = RealMessageDef()
-
- if init then
- for _, f in pairs(init.fields or {}) do
- m:add(f)
- end
- init.fields = nil
- set_named(m, init)
+-- MessageDef constructor; a wrapper around the real constructor that can
+-- set initial properties.
+--
+-- User can specify initialization values like so:
+-- upb.MessageDef{full_name="MyMessage", extstart=8000, fields={...}}
+upb.MessageDef = function(init)
+ local m = RealMessageDef()
+
+ if init then
+ for _, f in pairs(init.fields or {}) do
+ m:add(f)
end
+ init.fields = nil
- return m
+ set_named(m, init)
end
- -- EnumDef constructor; a wrapper around the real constructor that can
- -- set initial properties.
- --
- -- User can specify initialization values like so:
- -- upb.EnumDef{full_name="MyEnum",
- -- values={
- -- {"FOO_VALUE_1", 1},
- -- {"FOO_VALUE_2", 2}
- -- }
- -- }
- upb.EnumDef = function(init)
- local e = RealEnumDef()
-
- if init then
- for _, val in pairs(init.values or {}) do
- e:add(val[1], val[2])
- end
- init.values = nil
-
- set_named(e, init)
+ return m
+end
+
+-- EnumDef constructor; a wrapper around the real constructor that can
+-- set initial properties.
+--
+-- User can specify initialization values like so:
+-- upb.EnumDef{full_name="MyEnum",
+-- values={
+-- {"FOO_VALUE_1", 1},
+-- {"FOO_VALUE_2", 2}
+-- }
+-- }
+upb.EnumDef = function(init)
+ local e = RealEnumDef()
+
+ if init then
+ for _, val in pairs(init.values or {}) do
+ e:add(val[1], val[2])
end
+ init.values = nil
- return e
+ set_named(e, init)
end
- -- SymbolTable constructor; a wrapper around the real constructor that can
- -- add an initial set of defs.
- upb.SymbolTable = function(defs)
- local s = RealSymbolTable()
+ return e
+end
- if defs then
- s:add(defs)
- end
+-- SymbolTable constructor; a wrapper around the real constructor that can
+-- add an initial set of defs.
+upb.SymbolTable = function(defs)
+ local s = RealSymbolTable()
- return s
+ if defs then
+ s:add(defs)
end
+
+ return s
end
+
+return upb
diff --git a/upb/bindings/lua/upb/pb.c b/upb/bindings/lua/upb/pb.c
index 920648f..bf82a9b 100644
--- a/upb/bindings/lua/upb/pb.c
+++ b/upb/bindings/lua/upb/pb.c
@@ -92,11 +92,9 @@ static const struct luaL_Reg toplevel_m[] = {
{NULL, NULL}
};
-int luaopen_upb_pb(lua_State *L) {
- luaopen_upb(L);
-
+int luaopen_upb_pb_c(lua_State *L) {
static char module_key;
- if (lupb_openlib(L, &module_key, "upb.pb", toplevel_m)) {
+ if (lupb_openlib(L, &module_key, "upb.pb_c", toplevel_m)) {
return 1;
}
diff --git a/upb/bindings/lua/upb/pb.lua b/upb/bindings/lua/upb/pb.lua
new file mode 100644
index 0000000..66b3909
--- /dev/null
+++ b/upb/bindings/lua/upb/pb.lua
@@ -0,0 +1,11 @@
+--[[--------------------------------------------------------------------
+
+ upb - a minimalist implementation of protocol buffers.
+
+ Copyright (c) 2009 Google Inc. See LICENSE for details.
+ Author: Josh Haberman <jhaberman@gmail.com>
+
+--------------------------------------------------------------------]]--
+
+require "upb"
+return require "upb.pb_c"
diff --git a/upb/bindings/lua/table.c b/upb/bindings/lua/upb/table.c
index e15382b..0907f58 100644
--- a/upb/bindings/lua/table.c
+++ b/upb/bindings/lua/upb/table.c
@@ -162,7 +162,7 @@ static const struct luaL_Reg lupbtable_toplevel_m[] = {
{NULL, NULL}
};
-int luaopen_upbtable(lua_State *L) {
+int luaopen_upb_table_c(lua_State *L) {
static char module_key;
if (lupb_openlib(L, &module_key, "upb.table", lupbtable_toplevel_m)) {
return 1;
diff --git a/upb/bindings/lua/upb/table.lua b/upb/bindings/lua/upb/table.lua
new file mode 100644
index 0000000..8a0a9c9
--- /dev/null
+++ b/upb/bindings/lua/upb/table.lua
@@ -0,0 +1,11 @@
+--[[--------------------------------------------------------------------
+
+ upb - a minimalist implementation of protocol buffers.
+
+ Copyright (c) 2009 Google Inc. See LICENSE for details.
+ Author: Josh Haberman <jhaberman@gmail.com>
+
+--------------------------------------------------------------------]]--
+
+require "upb"
+return require "upb.table_c"
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback