Exemple #1
0
void LuaManager::ConvertVec3ToTable(const XMFLOAT3& vec, LuaPlus::LuaObject& outLuaTable) const
{
	outLuaTable.AssignNewTable(GetLuaState());
	outLuaTable.SetNumber("x", vec.x);
	outLuaTable.SetNumber("y", vec.y);
	outLuaTable.SetNumber("z", vec.z);
}
 void ModuleLoading::VInit()
 {
     fastdelegate::FastDelegate1<const char*> delegate =
                     fastdelegate::MakeDelegate(this, &ModuleLoading::LoadModule);
     
     module(GetLuaState(), "library")
     [
         def(
             "loadModule",
             tag_function<void(const char*)>(delegate)
             )
     ];
 }
bool ReadScriptDescriptor::RunScriptFunction(const std::string& function_name) {
	if (!IsFileOpen()) {
		PRINT_ERROR << "Can't call function " << function_name << "without opening a script file." << std::endl;
		return false;
	}

	try {
	    ScriptCallFunction<void>(GetLuaState(), function_name.c_str());
	} catch(luabind::error e) {
		PRINT_ERROR << "Error while loading :" << function_name << std::endl;
		ScriptManager->HandleLuaError(e);
		return false;
	}
	return true;
}
bool ReadScriptDescriptor::ExecuteFunction(const string& function_name) {
	if (IsFileOpen() == false) {
		IF_PRINT_WARNING(SCRIPT_DEBUG) << "function invoked when the file was not open: " << _filename << endl;
		return false;
	}

	try {
	    ScriptCallFunction<void>(GetLuaState(), function_name.c_str());
	}
	catch (luabind::error e) {
		IF_PRINT_WARNING(SCRIPT_DEBUG) << "caught Luabind error while trying to execute function \"" << function_name
			<< "\" in file: " << _filename << endl;
		ScriptManager->HandleLuaError(e);
		return false;
	}

	return true;
}
Exemple #5
0
intptr_t LUAPLUG ProcessEditorEventW (const struct ProcessEditorEventInfo *Info)
{
  intptr_t ret = 0;
  lua_State *L = GetLuaState();

  if (L && Api.GetExportFunction(L, "ProcessEditorEvent"))     //+1: Func
  {
    lua_pushinteger(L, Info->EditorID); //+2;
    lua_pushinteger(L, Info->Event);    //+3;

    switch (Info->Event)
    {
      case EE_CHANGE:
      {
        const struct EditorChange *ec = (const struct EditorChange*) Info->Param;
        lua_createtable(L, 0, 2);
        Api.PutNumToTable(L, "Type", ec->Type);
        Api.PutNumToTable(L, "StringNumber", (double)(ec->StringNumber+1));
        break;
      }
      case EE_SAVE:
      {
        struct EditorSaveFile *esf = (struct EditorSaveFile*)Info->Param;
        lua_createtable(L, 0, 3);
        Api.PutWStrToTable(L, "FileName", esf->FileName, -1);
        Api.PutWStrToTable(L, "FileEOL", esf->FileEOL, -1);
        Api.PutIntToTable(L, "CodePage", esf->CodePage);
        break;
      }
      default:
        lua_pushinteger(L, (intptr_t)Info->Param);
        break;
    }

    if(Api.pcall_msg(L, 3, 1) == 0)       //+1
    {
      if (lua_isnumber(L,-1)) ret = lua_tointeger(L,-1);

      lua_pop(L,1);
    }
  }

  return ret;
}
Exemple #6
0
static int SyncTableIndex(lua_State* dstL)
{
	if (lua_isnoneornil(dstL, -1))
		return 0;

	auto slh  = CLuaHandleSynced::GetSyncedHandle(dstL);
	if (!slh->IsValid())
		return 0;
	auto srcL = slh->GetLuaState();

	const int srcTop = lua_gettop(srcL);
	const int dstTop = lua_gettop(dstL);

	// copy the index & get value
	lua_pushvalue(srcL, LUA_GLOBALSINDEX);
	const int keyCopied = LuaUtils::CopyData(srcL, dstL, 1);
	assert(keyCopied > 0);
	lua_rawget(srcL, -2);

	// copy to destination
	const int valueCopied = LuaUtils::CopyData(dstL, srcL, 1);
	if (lua_istable(dstL, -1)) {
		// disallow writing in SYNCED[...]
		lua_newtable(dstL); { // the metatable
			LuaPushNamedCFunc(dstL, "__newindex",  SyncTableNewIndex);
			LuaPushNamedCFunc(dstL, "__metatable", SyncTableMetatable);
		}
		lua_setmetatable(dstL, -2);
	}

	assert(valueCopied == 1);
	assert(dstTop + 1 == lua_gettop(dstL));

	lua_settop(srcL, srcTop);
	return valueCopied;
}
Exemple #7
0
int lib_open(klibrary_t * lib) {
	luaopen_task(GetLuaState());
	RegisterLuaLib(lib_get_name(), (LuaRegLibOpen *)luaopen_task);
	return nmmgr_handler_add(&ds_luaTask_hnd.nmmgr);
}
Exemple #8
0
int lib_open(klibrary_t * lib) {
    tolua_STD_open(GetLuaState());
	RegisterLuaLib(lib_get_name(), (LuaRegLibOpen *)tolua_STD_open);
    return nmmgr_handler_add(&ds_luaSTD_hnd.nmmgr);
}