本文整理汇总了C++中LuaState类的典型用法代码示例。如果您正苦于以下问题:C++ LuaState类的具体用法?C++ LuaState怎么用?C++ LuaState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LuaState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: outputFunc
void outputFunc(std::string file, std::string func, const std::string& str, std::vector<any> args)
{
LuaState ls;
openUtilExtendLibs(ls.getState());
int err = ls.parseFile(file);
if (0 != err)
{
printLine(luaGetError(ls.getState(), err));
return;
}
luaGetGlobal(ls.getState(), func);
luaPushString(ls.getState(), str);
for (size_t i=0; i<args.size(); ++i)
luaPushAny(ls.getState(), args[i]);
err = luaCallFunc(ls.getState(), 1 + args.size() , 0);
if (0 != err)
{
printLine(luaGetError(ls.getState(), err));
return;
}
luaPop(ls.getState(), -1);
}
示例2: Update
void CCallStackDlg::Update()
{
m_list.DeleteAllItems();
LuaState* state = theApp.GetDocument()->GetState();
LuaObject callStackTableObj = state->GetGlobals()[ "CallStack" ];
if (callStackTableObj.IsTable())
{
int index = 1;
while (true)
{
LuaObject callTableObj = callStackTableObj.GetByIndex(index++);
if (callTableObj.IsNil())
break;
LuaObject nameObj = callTableObj.GetByIndex(1);
LuaObject typeObj = callTableObj.GetByIndex(2);
LuaObject lineNumberObj = callTableObj.GetByIndex(3);
CString str;
if (lineNumberObj.GetInteger() != -1)
str.Format(_T(" line %d"), lineNumberObj.GetInteger());
str = nameObj.GetString() + str + _T(" (") + typeObj.GetString() + _T(")");
m_list.InsertItem(m_list.GetItemCount(), str);
}
}
}
示例3: toLua
void LuaTable::toLua(LuaState& lua) const {
lua.createTable(intKeys.size(), stringKeys.size());
std::for_each(std::begin(intKeys), std::end(intKeys),
[&](std::pair<const int, unsigned> intKey)->void {
lua.pushStack(intKey.first);
pushAnyValue(lua, types[intKey.second], values[intKey.second]);
lua.setTable();
});
std::for_each(std::begin(stringKeys), std::end(stringKeys),
[&](std::pair<const std::string, unsigned> stringKey)->void {
lua.pushStack(stringKey.first);
pushAnyValue(lua, types[stringKey.second], values[stringKey.second]);
lua.setTable();
});
}
示例4: fromLua
void LuaTable::fromLua(LuaState& lua) {
std::for_each(std::begin(intKeys), std::end(intKeys),
[&](std::pair<const int, unsigned> intKey)->void {
int x = 0;
lua.getTable(intKey.first);
pullAnyValue(lua, types[intKey.second], values[intKey.second]);
lua.popStack();
});
std::for_each(std::begin(stringKeys), std::end(stringKeys),
[&](std::pair<const std::string, unsigned> stringKey)->void {
lua.getTable(stringKey.first);
pullAnyValue(lua, types[stringKey.second], values[stringKey.second]);
lua.popStack();
});
}
示例5:
/*static*/ LuaState* LuaState::Create(bool initStandardLibrary)
{
LuaState* state = LuaState::Create();
if (initStandardLibrary)
state->OpenLibs();
return state;
}
示例6: luaplus_assert
/**
Go to the next entry in the table.
\return Returns true if the iteration is done.
**/
bool LuaStackTableIterator::Next()
{
// This function is only active if Reset() has been called head.
luaplus_assert( IsValid() );
// This is a local helper variable so we don't waste space in the class
// definition.
LuaState* state = m_tableObj.GetState();
// Do any stack management operations.
if ( m_autoStackManagement )
{
state->SetTop( m_startStackIndex + 1 );
}
else
{
// If this luaplus_assert fires, then you left something on the stack.
luaplus_assert( state->GetTop() == m_startStackIndex + 1 );
}
// Do the Lua table iteration.
if ( state->Next( m_tableObj ) == 0 )
{
// Invalidate the iterator.
m_startStackIndex = -1;
return false;
}
// The iterator is still valid.
return true;
}
示例7: LuaError
int LuaState::LuaError(lua_State* luaState)
{
LuaState* wrapper = LuaState::GetWrapper(luaState);
assert(wrapper);
wrapper->OnError();
return 0;
}
示例8: lua_getdefaultallocfunction
/*static*/ LuaState* LuaState::CreateMT(bool initStandardLibrary)
{
lua_Alloc reallocFunc;
void* data;
lua_getdefaultallocfunction(&reallocFunc, &data);
LuaState* state = (LuaState*)(*reallocFunc)(data, NULL, 0, sizeof(LuaState), "LuaState", 0);
::new(state) LuaState(true);
state->OpenLibs();
return state;
}
示例9: main
int main(int argc, char** argv)
{
LuaState* pstate = LuaState::Create(true);
pstate->GetGlobals().Register("TestFunc", TestFunc);
const char* szCmd = "TestFunc('hahhahhahh');";
pstate->DoString(szCmd);
LuaState::Destroy(pstate);
return 0;
}
示例10: lock
LuaState* LuaState::luaForThread( sys::Thread& thread, unsigned int id, const char* init )
{
sys::LockEnterLeave lock( s_lock );
//
// create new lua state for new thread
//
LuaState* lua = Leda::instance()->newLua();
lua->load( id, false, init );
thread.setData( lua );
return lua;
}
示例11: loadFromDef
/*bool TileType::loadFromDef(JsonValue value)
{
if (value.has("fullName", JV_STR))
{
mFullName = value["fullName"].getCStr();
}
return true;
}*/
bool TileType::loadFromDef(LuaState &lua)
{
if (!lua_istable(lua, -1))
{
return false;
}
if (lua.isTableString("fullName"))
{
mFullName = lua_tostring(lua, -1);
lua.pop(1);
}
return true;
}
示例12: testSimple
bool TestLuaTileSet::testSimple() {
LuaState lua;
assert(lua.loadString("TileSet = import(\"TileSet\")\n"
"set = TileSet.new(\"testTileSet\")\n"
"function getName()\n"
" return set:name()\n"
"end\n"
"function getFullName()\n"
" return set:full_name()\n"
"end\n"
"function setFullName(name)\n"
" set:full_name(name)\n"
"end\n"
));
assert(lua.hasGlobalFunction("getName"));
lua_acall(lua, 0, 1);
am_equalsStr("testTileSet", lua_tostring(lua, -1));
lua.pop(1);
assert(lua.hasGlobalFunction("setFullName"));
lua.push("New Full Name");
lua_acall(lua, 1, 0);
assert(lua.hasGlobalFunction("getFullName"));
lua_acall(lua, 0, 1);
am_equalsStr("New Full Name", lua_tostring(lua, -1));
lua.pop(1);
return true;
}
示例13: LuaPlusGCFunction
void LuaPlusGCFunction(void* s)
{
GCState* st = (GCState*)s;
LuaState* state = (LuaState*)lua_getstateuserdata(st->L);
if (!state)
return;
LuaObject* curObj = state->GetHeadObject()->m_next;
while (curObj != state->GetTailObject())
{
markobject(st, &curObj->m_object);
curObj = curObj->m_next;
}
}
示例14: Reset
/**
Start iteration at the beginning of the table.
**/
void LuaStackTableIterator::Reset()
{
// Start afresh...
LuaState* state = m_tableObj.GetState();
m_startStackIndex = state->GetTop();
// Push the head stack entry.
state->PushNil();
// Start the iteration. If the return value is 0, then the iterator
// will be invalid.
if ( state->Next( m_tableObj ) == 0 )
m_startStackIndex = -1;
}
示例15: luaopen_bit
extern "C" LUAMODULE_API int luaopen_bit(lua_State* L)
{
LuaState* state = LuaState::CastState(L);
LuaObject obj = state->GetGlobals().CreateTable( "bit" );
obj.Register("bnot", int_bnot);
obj.Register("band", int_band);
obj.Register("bor", int_bor);
obj.Register("bxor", int_bxor);
obj.Register("lshift", int_lshift);
obj.Register("rshift", int_rshift);
obj.Register("arshift", int_arshift);
obj.Register("mod", int_mod);
obj.Register("help", LS_help);
return 0;
}