Skip to content

Commit

Permalink
[lua] added tz::lua::state::assign_emptyable
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Aug 6, 2023
1 parent b5e2921 commit b70d1e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/tz/lua/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ namespace tz::lua
return this->execute(cmd.c_str(), false);
}

bool state::assign_emptytable(const char* varname) const
{
std::string cmd = std::string(varname) + " = {}";
return this->execute(cmd.c_str(), false);
}

bool state::assign_bool(const char* varname, bool b) const
{
std::string cmd = std::string(varname) + " = " + std::to_string(b);
Expand Down Expand Up @@ -158,7 +164,8 @@ namespace tz::lua

void tz_inject_state(state& s)
{
s.execute("tz = {}; tz.version = {}");
s.assign_emptytable("tz");
s.assign_emptytable("tz.version");
s.assign_func("tz.assert", tz_lua_assert);

tz::version ver = tz::get_version();
Expand Down
1 change: 1 addition & 0 deletions src/tz/lua/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace tz::lua
bool execute(const char* lua_src, bool assert_on_failure = true) const;

bool assign_nil(const char* varname) const;
bool assign_emptytable(const char* varname) const;
bool assign_bool(const char* varname, bool b) const;
bool assign_float(const char* varname, float f) const;
bool assign_double(const char* varname, double d) const;
Expand Down

0 comments on commit b70d1e6

Please sign in to comment.