Files
fastweb/src/core/global.cpp
2024-06-03 19:08:24 +08:00

65 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "global.h"
#include "module/imodule.h"
global::global()
{
}
void global::regist_lua(sol::state* lua)
{
m_value_ptr.lock();
for_iter(iter, (*m_value_ptr.parent()))
{
auto im = static_cast<module::imodule*>(iter->second);
im->regist_global(iter->first, lua);
}
m_value_ptr.unlock();
}
void* global::get_ptr(const std::string& name)
{
void* result = nullptr;
m_value_ptr.get(name,result);
return result;
}
bool global::regist_ptr(const std::string& name, void* value, sol::this_state ts)
{
sol::state_view lua(ts);
// INIT中先注册一次防止被销毁
{
lua.registry()[name] = this;
lua[name] = this;
}
return m_value_ptr.add(name, value);
}
VarType global::get(const std::string& name, sol::this_state s)
{
VarType value;
if (m_values.get(name, value))
{
return value;
}
return sol::make_object(s, sol::nil);
}
void global::set(const std::string& name, VarType value)
{
m_values.set(name, value, true);
}
void global::clear()
{
m_values.clear();
m_value_ptr.clear();
//m_value_ptr.lock();
//for_iter(iter, (*m_value_ptr.parent()))
//{
// auto im = static_cast<module::imodule*>(iter->second);
// im->delete_global();
//}
//m_value_ptr.unlock();
//m_value_ptr.clear();
}