• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--[[--------------------------------------------------------------------------
2
3Protocol Buffers - Google's data interchange format
4Copyright 2023 Google LLC.  All rights reserved.
5
6Use of this source code is governed by a BSD-style
7license that can be found in the LICENSE file or at
8https://developers.google.com/open-source/licenses/bsd
9
10--]]--------------------------------------------------------------------------
11
12local upb = require("lupb")
13
14upb.generated_pool = upb.DefPool()
15
16local module_metatable = {
17  __index = function(t, k)
18    local package = t._filedef:package()
19    if package then
20      k = package .. "." .. k
21    end
22    local pool = upb.generated_pool
23    local def = pool:lookup_msg(k) or pool:lookup_enum(k)
24    local v = nil
25    if def and def:file():name() == t._filedef:name() then
26      v = def
27      t[k] = v
28    end
29    return v
30  end
31}
32
33function upb._generated_module(desc_string)
34  local file = upb.generated_pool:add_file(desc_string)
35  local module = {_filedef = file}
36  setmetatable(module, module_metatable)
37  return module
38end
39
40return upb
41