65 lines
1.2 KiB
C++
65 lines
1.2 KiB
C++
|
||
#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();
|
||
}
|