• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

traintastic / traintastic / 24288605255

11 Apr 2026 06:17PM UTC coverage: 25.599% (-2.4%) from 27.99%
24288605255

push

github

web-flow
Merge pull request #222 from traintastic/cbus

Added CBUS/VLCB hardware support

169 of 3369 new or added lines in 99 files covered. (5.02%)

5 existing lines in 4 files now uncovered.

8300 of 32423 relevant lines covered (25.6%)

178.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.5
/server/src/lua/object.cpp
1
/**
2
 * This file is part of Traintastic,
3
 * see <https://github.com/traintastic/traintastic>.
4
 *
5
 * Copyright (C) 2019-2026 Reinder Feenstra
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 */
21

22
#include "object.hpp"
23
#include "object/object.hpp"
24
#include "object/objectlist.hpp"
25
#include "object/interface.hpp"
26
#include "object/cbusinterface.hpp"
27
#include "object/loconetinterface.hpp"
28
#include "object/scriptthrottle.hpp"
29

30
namespace Lua::Object {
31

32
constexpr char const* objectsGlobal = "objects";
33

34
void registerTypes(lua_State* L)
99✔
35
{
36
  Object::registerType(L);
99✔
37
  ObjectList::registerType(L);
99✔
38
  Interface::registerType(L);
99✔
39
  CBUSInterface::registerType(L);
99✔
40
  LocoNetInterface::registerType(L);
99✔
41
  ScriptThrottle::registerType(L);
99✔
42

43
  // weak table for object userdata:
44
  lua_newtable(L);
99✔
45
  lua_newtable(L); // metatable
99✔
46
  lua_pushliteral(L, "__mode");
99✔
47
  lua_pushliteral(L, "v");
99✔
48
  lua_rawset(L, -3);
99✔
49
  lua_setmetatable(L, -2);
99✔
50
  lua_setglobal(L, objectsGlobal);
99✔
51
}
99✔
52

53
void push(lua_State* L, ::Object& value)
×
54
{
55
  push(L, value.shared_from_this());
×
56
}
×
57

58
void push(lua_State* L, const ObjectPtr& value)
117✔
59
{
60
  if(value)
117✔
61
  {
62
    lua_getglobal(L, objectsGlobal);
117✔
63
    lua_rawgetp(L, -1, value.get());
117✔
64
    if(lua_isnil(L, -1)) // object not in table
117✔
65
    {
66
      lua_pop(L, 1); // remove nil
114✔
67
      new(lua_newuserdata(L, sizeof(ObjectPtrWeak))) ObjectPtrWeak(value);
114✔
68

69
      if(dynamic_cast<::CBUSInterface*>(value.get()))
114✔
70
      {
NEW
71
        luaL_setmetatable(L, CBUSInterface::metaTableName);
×
72
      }
73
      else if(dynamic_cast<::LocoNetInterface*>(value.get()))
114✔
74
        luaL_setmetatable(L, LocoNetInterface::metaTableName);
1✔
75
      else if(dynamic_cast<AbstractObjectList*>(value.get()))
113✔
76
        luaL_setmetatable(L, ObjectList::metaTableName);
×
77
      else if(dynamic_cast<::ScriptThrottle*>(value.get()))
113✔
78
      {
79
        luaL_setmetatable(L, ScriptThrottle::metaTableName);
×
80
      }
81
      else
82
        luaL_setmetatable(L, Object::metaTableName);
113✔
83

84
      lua_pushvalue(L, -1); // copy userdata on stack
114✔
85
      lua_rawsetp(L, -3, value.get()); // add object to table
114✔
86
    }
87
    lua_insert(L, lua_gettop(L) - 1); // swap table and userdata
117✔
88
    lua_pop(L, 1); // remove table
117✔
89
  }
90
  else
91
    lua_pushnil(L);
×
92
}
117✔
93

94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc